diff --git a/src/features/vcs/__tests__/compareFlow.test.ts b/src/features/vcs/__tests__/compareFlow.test.ts index 16aa4889dc..a93fd9adb0 100644 --- a/src/features/vcs/__tests__/compareFlow.test.ts +++ b/src/features/vcs/__tests__/compareFlow.test.ts @@ -1,4 +1,5 @@ import { afterEach, describe, expect, it, vi } from "vitest"; +import type { FileStatus } from "@/bindings"; const mocks = vi.hoisted(() => ({ scope: vi.fn(), @@ -93,4 +94,21 @@ describe("comparison flow", () => { expect(await showDirectoryWorkingDiff([path])).toBe(false); expect(mocks.show).not.toHaveBeenCalled(); }); + + it("opens changed files as the file diff chain instead of a comparison window", async () => { + const files = ["/server/a.ts", "/server/b.ts"].map((path) => ({ + path, + relPath: path.slice("/server/".length), + unstaged: "modified", + staged: null, + renamedFrom: null, + })) as FileStatus[]; + useVcs.setState({ status: files, byPath: new Map(files.map((f) => [f.path, f])) }); + mocks.scope.mockResolvedValue({ + status: "ok", + data: { repositories: ["/server"], singleFile: false, skippedPaths: [] }, + }); + expect(await showDirectoryWorkingDiff(["/server/a.ts", "/server/b.ts"])).toBe(false); + expect(mocks.show).not.toHaveBeenCalled(); + }); }); diff --git a/src/features/vcs/__tests__/show-diff-chain.test.ts b/src/features/vcs/__tests__/show-diff-chain.test.ts index 9818506ef1..498e18b3bf 100644 --- a/src/features/vcs/__tests__/show-diff-chain.test.ts +++ b/src/features/vcs/__tests__/show-diff-chain.test.ts @@ -169,6 +169,16 @@ it("keeps the front diff dialog when the diff window cannot open", async () => { expect(closeOpenDiffDialog).not.toHaveBeenCalled(); }); +it("opens a changelist-node selection of several changed files as one diff chain", async () => { + setContext("activeToolWindow", "commit"); + useCommit.setState({ selection: ["/repo/a.ts", "/repo/b.ts", "/repo/z.ts"] }); + await getAction("vcs.showDiff")!.run({ arg: undefined, ctx: { vcsAvailable: true } }); + expect(opened).toHaveBeenCalledTimes(1); + const data = opened.mock.calls[0]![0].data; + expect(data.path).toBe("/repo/a.ts"); + expect(data.chain.map((d: { path: string }) => d.path)).toEqual(["/repo/a.ts", "/repo/b.ts", "/repo/z.ts"]); +}); + it("opens the front diff window from the modal Local Changes selection (⌘D)", async () => { modal(); setContext("activeToolWindow", "git"); diff --git a/src/features/vcs/actions.tsx b/src/features/vcs/actions.tsx index ea33d1d670..68c818d6f6 100644 --- a/src/features/vcs/actions.tsx +++ b/src/features/vcs/actions.tsx @@ -936,6 +936,18 @@ export function registerVcsActions(): () => void { await openVcsDiff({ ...data, line }); return; } + // Several selected changed files (a changelist node) open as one diff chain, + // as the modal interface does; a path that the tree lists once keeps its group. + if (targets.length > 1 && targets.every((t) => typeof t !== "string")) { + await openVcsDiff({ + ...withChain( + targets.map((t) => changeNodeDiff(t)), + 0, + ), + line, + }); + return; + } for (const target of targets.slice(0, 5)) { const data = typeof target === "string" ? groupDiffData(tree, target) : changeNodeDiffData(tree, target); // oxlint-disable-next-line no-await-in-loop -- diff tabs open in selection order diff --git a/src/features/vcs/comparePaths.ts b/src/features/vcs/comparePaths.ts index dbf9aef5ca..ef511128f8 100644 --- a/src/features/vcs/comparePaths.ts +++ b/src/features/vcs/comparePaths.ts @@ -46,6 +46,9 @@ export async function showDirectoryWorkingDiff(paths: string[]): Promise statusOf(path))) { const entries = await loadDiffEntries(paths.flatMap((path) => ["WT", ":0", "HEAD"].map((rev) => ({ path, rev })))); if (entries?.some((entry) => entry?.mode === GITLINK_MODE)) return false; + // A selection of changed files (a changelist node, several file rows) opens the + // file diff chain, like a single file does; the comparison stays for directories. + return false; } if (!scope.repositories.length) { notifications().notify({