Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const ChangesTabContent = memo(function ChangesTabContent({
filter={filter}
onFilterChange={onFilterChange}
commits={commits.data?.commits ?? []}
workspaceId={workspaceId}
uncommittedCount={
status.data.staged.length + status.data.unstaged.length
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface ChangesToolbarProps {
filter: ChangesFilter;
onFilterChange: (filter: ChangesFilter) => void;
commits: Commit[];
workspaceId: string;
uncommittedCount: number;
totalFiles: number;
totalAdditions: number;
Expand All @@ -39,6 +40,7 @@ export function ChangesToolbar({
filter,
onFilterChange,
commits,
workspaceId,
uncommittedCount,
totalFiles,
totalAdditions,
Expand All @@ -59,6 +61,7 @@ export function ChangesToolbar({
filter={filter}
onFilterChange={onFilterChange}
commits={commits}
workspaceId={workspaceId}
uncommittedCount={uncommittedCount}
/>
<span className="whitespace-nowrap">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ interface CommitFilterDropdownProps {
filter: ChangesFilter;
onFilterChange: (filter: ChangesFilter) => void;
commits: Commit[];
workspaceId: string;
uncommittedCount?: number;
}

export function CommitFilterDropdown({
filter,
onFilterChange,
commits,
workspaceId,
uncommittedCount,
}: CommitFilterDropdownProps) {
const [rangeModalOpen, setRangeModalOpen] = useState(false);
Expand Down Expand Up @@ -106,6 +108,7 @@ export function CommitFilterDropdown({
>
<CommitRow
commit={commit}
workspaceId={workspaceId}
isSelected={
filter.kind === "commit" && filter.hash === commit.hash
}
Expand All @@ -121,6 +124,7 @@ export function CommitFilterDropdown({
open={rangeModalOpen}
onOpenChange={setRangeModalOpen}
commits={commits}
workspaceId={workspaceId}
onSelect={(fromHash, toHash) =>
onFilterChange({ kind: "range", fromHash, toHash })
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { AppRouter } from "@superset/host-service";
import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip";
import { workspaceTrpc } from "@superset/workspace-client";
import type { inferRouterOutputs } from "@trpc/server";
import { Check } from "lucide-react";
import { useState } from "react";

type Commit =
inferRouterOutputs<AppRouter>["git"]["listCommits"]["commits"][number];
Expand All @@ -18,26 +21,74 @@ function timeAgo(date: string): string {

interface CommitRowProps {
commit: Commit;
workspaceId: string;
isSelected?: boolean;
wrap?: boolean;
}

export function CommitRow({
commit,
workspaceId,
isSelected,
wrap = false,
}: CommitRowProps) {
const [open, setOpen] = useState(false);

// listCommits only carries `%s`, so the body is fetched per commit and only
// once the card is actually opened. Commit messages are immutable, so a
// hover that reopens the same card never refetches.
const message = workspaceTrpc.git.getCommitMessage.useQuery(
{ workspaceId, commitHash: commit.hash },
{ enabled: open, staleTime: Number.POSITIVE_INFINITY },
);
const subject = message.data?.subject ?? commit.message;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When the on-demand getCommitMessage fetch fails, the tooltip silently falls back to the commit subject and an empty body (subject = message.data?.subject ?? commit.message, body = message.data?.body ?? ""), so a failed read is indistinguishable from a commit that genuinely has no body. Since surfacing the full message is the entire point of this hover interaction, a user who sees the tooltip after a load failure will reasonably conclude the commit has no body. Consider surfacing the failure — e.g. an error note and/or a retry — when message.isError is set, while still keeping the subject as the graceful fallback for the brief loading window.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/components/WorkspaceSidebar/hooks/useChangesTab/components/CommitFilterDropdown/components/CommitRow/CommitRow.tsx, line 44:

<comment>When the on-demand getCommitMessage fetch fails, the tooltip silently falls back to the commit subject and an empty body (`subject = message.data?.subject ?? commit.message`, `body = message.data?.body ?? ""`), so a failed read is indistinguishable from a commit that genuinely has no body. Since surfacing the full message is the entire point of this hover interaction, a user who sees the tooltip after a load failure will reasonably conclude the commit has no body. Consider surfacing the failure — e.g. an error note and/or a retry — when `message.isError` is set, while still keeping the subject as the graceful fallback for the brief loading window.</comment>

<file context>
@@ -18,26 +21,74 @@ function timeAgo(date: string): string {
+		{ workspaceId, commitHash: commit.hash },
+		{ enabled: open, staleTime: Number.POSITIVE_INFINITY },
+	);
+	const subject = message.data?.subject ?? commit.message;
+	const body = message.data?.body ?? "";
+
</file context>

const body = message.data?.body ?? "";

return (
<div className="flex min-w-0 flex-1 items-start justify-between gap-2">
<div className="min-w-0 flex-1 overflow-hidden">
<div className={wrap ? "text-sm wrap-break-word" : "truncate text-sm"}>
{commit.message}
<Tooltip open={open} onOpenChange={setOpen} delayDuration={400}>
<TooltipTrigger asChild>
<div className="flex min-w-0 flex-1 items-start justify-between gap-2">
<div className="min-w-0 flex-1 overflow-hidden">
<div
className={wrap ? "text-sm wrap-break-word" : "truncate text-sm"}
>
{commit.message}
</div>
<div className="truncate text-xs text-muted-foreground">
{commit.shortHash} · {commit.author} · {timeAgo(commit.date)}
</div>
</div>
{isSelected && <Check className="mt-0.5 size-3.5 shrink-0" />}
</div>
</TooltipTrigger>
{/* The arrow points back at the hovered row, which matters in a list
this dense. Only the message scrolls: bodies are unbounded, and a
long one would otherwise grow the card past the window — the
arrow and the hash line have to stay put and visible.
The card is wide enough for a conventionally wrapped body (~72
columns) so the message is not re-wrapped into a ragged column
on top of the author's own line breaks. */}
<TooltipContent
side="left"
align="start"
showArrow
collisionPadding={8}
className="w-[26rem] max-w-[calc(100vw-6rem)] p-0 text-wrap"
>
<div className="max-h-64 overflow-y-auto px-2.5 py-2">
<div className="font-medium text-foreground wrap-break-word">
{subject}
</div>
{body && (
<div className="mt-1.5 cursor-text select-text whitespace-pre-wrap font-normal leading-relaxed wrap-break-word">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Remove text-selection styling from the hover tooltip.

TooltipContent dismisses when the pointer leaves its trigger. The cursor-text select-text classes invite selection, but moving the pointer to select the body dismisses the tooltip. Remove these classes. Use a persistent surface if users must copy commit bodies.

Based on learnings, do not use select-text or cursor-text in hover-dismissable tooltip content.

Proposed fix
-						<div className="mt-1.5 cursor-text select-text whitespace-pre-wrap font-normal leading-relaxed wrap-break-word">
+						<div className="mt-1.5 whitespace-pre-wrap font-normal leading-relaxed wrap-break-word">
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div className="mt-1.5 cursor-text select-text whitespace-pre-wrap font-normal leading-relaxed wrap-break-word">
<div className="mt-1.5 whitespace-pre-wrap font-normal leading-relaxed wrap-break-word">
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/`$workspaceId/components/WorkspaceSidebar/hooks/useChangesTab/components/CommitFilterDropdown/components/CommitRow/CommitRow.tsx
at line 83, Remove the cursor-text and select-text classes from the div inside
TooltipContent in CommitRow, while preserving the remaining layout and
text-wrapping classes. Do not add alternative text-selection behavior to the
hover-dismissable tooltip.

Source: Learnings

{body}
</div>
)}
</div>
<div className="truncate text-xs text-muted-foreground">
<div className="border-border border-t px-2.5 py-1.5 font-normal text-[11px] text-muted-foreground/70">
{commit.shortHash} · {commit.author} · {timeAgo(commit.date)}
</div>
</div>
{isSelected && <Check className="mt-0.5 size-3.5 shrink-0" />}
</div>
</TooltipContent>
</Tooltip>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ interface RangeModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
commits: Commit[];
workspaceId: string;
onSelect: (fromHash: string, toHash: string) => void;
}

export function RangeModal({
open,
onOpenChange,
commits,
workspaceId,
onSelect,
}: RangeModalProps) {
const [fromIdx, setFromIdx] = useState<number | null>(null);
Expand Down Expand Up @@ -95,7 +97,7 @@ export function RangeModal({
: "hover:bg-accent/50"
}`}
>
<CommitRow commit={commit} wrap />
<CommitRow commit={commit} workspaceId={workspaceId} wrap />
</button>
);
})}
Expand Down
34 changes: 34 additions & 0 deletions packages/host-service/src/trpc/router/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import type { HostServiceContext } from "../../../types";
import { getHostWorkerPool } from "../../../workers/host-worker-pool";
import {
gitCommitFilesTask,
gitCommitMessageTask,
gitFetchBaseRefTask,
gitStatusSnapshotTask,
} from "../../../workers/tasks/git";
import { protectedProcedure, queryProcedure, router } from "../../index";
import { offLoop } from "../../off-loop";
import { resolveGithubRepo } from "../workspace-creation/shared/project-helpers";
import type {
ChangedFile,
Expand All @@ -28,6 +30,7 @@ import type {
PullRequestState,
} from "./types";
import { scheduleBaseRefFetch } from "./utils/base-ref-freshness";
import { isValidCommitHash } from "./utils/commit-message";
import { gitConfigWrite } from "./utils/config-write";
import {
getDefaultBranchName,
Expand Down Expand Up @@ -267,6 +270,37 @@ export const gitRouter = router({
return { files };
}),

/**
* Subject + body for one commit. listCommits only carries `%s`, so this is
* the only way to read a commit's body without leaving the app.
*/
getCommitMessage: queryProcedure
.meta({ timeoutMs: 15_000 })
.input(
z.object({
workspaceId: z.string(),
commitHash: z.string().refine(isValidCommitHash, "Not a commit hash"),
}),
)
.query(
offLoop({
task: gitCommitMessageTask,
prepare: async ({ ctx, input }) => {
const worktreePath = resolveWorktreePath(ctx, input.workspaceId);
return {
worktreePath,
commitHash: input.commitHash,
gitEnv: await resolveGitTaskEnv(ctx, worktreePath),
};
},
options: ({ input }) => ({
timeoutMs: 15_000,
strategy: "coalesce",
dedupeKey: `${input.workspaceId}:commit-message:${input.commitHash}`,
}),
}),
),

getBaseBranch: queryProcedure
.input(z.object({ workspaceId: z.string() }))
.query(async ({ ctx, input }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { describe, expect, test } from "bun:test";
import { isValidCommitHash, splitCommitMessage } from "./commit-message";

describe("splitCommitMessage", () => {
test("subject-only message has an empty body", () => {
expect(splitCommitMessage("fix(ui): tighten chip spacing\n")).toEqual({
subject: "fix(ui): tighten chip spacing",
body: "",
});
});

test("splits subject from body at the first blank line", () => {
const raw =
"feat(landing): peraga cara kerja\n\nContoh Adem diganti marjan.\n";

expect(splitCommitMessage(raw)).toEqual({
subject: "feat(landing): peraga cara kerja",
body: "Contoh Adem diganti marjan.",
});
});

test("preserves blank lines and indentation inside the body", () => {
const raw = ["subject", "", "para one", "", " - indented bullet", ""].join(
"\n",
);

expect(splitCommitMessage(raw).body).toBe(
"para one\n\n - indented bullet",
);
});

test("keeps trailers, which is where Co-Authored-By lives", () => {
const raw =
"subject\n\nwhy this change\n\nCo-Authored-By: Someone <someone@example.com>\n";

expect(splitCommitMessage(raw).body).toContain(
"Co-Authored-By: Someone <someone@example.com>",
);
});

test("folds a wrapped subject onto one line, matching %s", () => {
const raw = "a subject that git\nwrapped across lines\n\nbody\n";

expect(splitCommitMessage(raw).subject).toBe(
"a subject that git wrapped across lines",
);
});

test("only the first blank line splits — later ones stay in the body", () => {
const raw = "subject\n\nfirst\n\nsecond\n";

expect(splitCommitMessage(raw)).toEqual({
subject: "subject",
body: "first\n\nsecond",
});
});

test("handles CRLF line endings", () => {
expect(splitCommitMessage("subject\r\n\r\nbody line\r\n")).toEqual({
subject: "subject",
body: "body line",
});
});

test("empty input yields empty subject and body", () => {
expect(splitCommitMessage("")).toEqual({ subject: "", body: "" });
});
});

describe("isValidCommitHash", () => {
test("accepts short, full, and uppercase hex object names", () => {
expect(isValidCommitHash("48aa309")).toBe(true);
expect(isValidCommitHash("b7bc64f4e2c1a09d3f5e8a7b6c4d2e1f0a9b8c7d")).toBe(
true,
);
expect(isValidCommitHash("48AA309")).toBe(true);
});

test("rejects flags and revision expressions", () => {
expect(isValidCommitHash("--output=/tmp/pwned")).toBe(false);
expect(isValidCommitHash("HEAD~1")).toBe(false);
expect(isValidCommitHash("HEAD; rm -rf /")).toBe(false);
expect(isValidCommitHash("feat/sveltekit-studio-db")).toBe(false);
});

test("rejects input that is too short or not hex", () => {
expect(isValidCommitHash("48aa3")).toBe(false);
expect(isValidCommitHash("")).toBe(false);
expect(isValidCommitHash("zzzzzzz")).toBe(false);
});
});
42 changes: 42 additions & 0 deletions packages/host-service/src/trpc/router/git/utils/commit-message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/** Full commit message, split the way git itself presents it. */
export interface CommitMessage {
/** First paragraph, folded to one line — matches `git log --format=%s`. */
subject: string;
/** Everything after the first blank line, verbatim. Empty when absent. */
body: string;
}

/**
* `git log --format=%s` collapses a multi-line first paragraph into a single
* line, so folding here keeps a popover header identical to the list row that
* opened it. Everything after the first blank line is the body and is left
* untouched — blank lines and indentation are meaningful in trailers and
* bullet lists.
*/
export function splitCommitMessage(raw: string): CommitMessage {
const normalized = raw.replace(/\r\n/g, "\n").replace(/^\n+/, "");
const separator = normalized.indexOf("\n\n");

if (separator === -1) {
return { subject: foldSubject(normalized), body: "" };
}

return {
subject: foldSubject(normalized.slice(0, separator)),
body: normalized.slice(separator + 2).replace(/\s+$/, ""),
};
}

function foldSubject(paragraph: string): string {
return paragraph.replace(/\s*\n\s*/g, " ").trim();
}

/**
* Restricts a ref to a hex object name before it reaches `git log`. Without
* this a caller could pass a flag (`--output=…`) or a revision expression
* (`HEAD~1`, a branch name) and read something other than the commit the UI
* is showing.
*/
export function isValidCommitHash(hash: string): boolean {
return /^[0-9a-fA-F]{7,64}$/.test(hash);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { eq } from "drizzle-orm";
import { workspaces } from "../../../../db/schema";
import type { protectedProcedure } from "../../../index";

/** Only `db` is read, so this also accepts the plain context an offLoop()
* `prepare` stage receives (where request-only fields are optional). */
export function resolveWorktreePath(
ctx: Parameters<Parameters<typeof protectedProcedure.query>[0]>[0]["ctx"],
ctx: Pick<
Parameters<Parameters<typeof protectedProcedure.query>[0]>[0]["ctx"],
"db"
>,
workspaceId: string,
): string {
const workspace = ctx.db.query.workspaces
Expand Down
Loading