Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 3c6f544280 fix(vcs): Show Diff of a staged or unstaged row shows that side of the index
The changes tree's Show Diff passed only the file's path to the action, which
opened HEAD against the working copy, so a partially staged file showed its
unstaged edit from the Staged group too. The menu item now opens the row's own
diff, as double-click does: HEAD ↔ Index under Staged, Index ↔ working copy under
Unstaged. Show Diff from the keyboard builds the tree the Commit window shows
(staging groups, no change lists, with the staging area) so the selected row is
found, and uses it with the non-modal interface too.

Fixes #4152
2026-11-18 18:44:55 +08:00
4 змінених файлів з 42 додано та 9 видалено

No files matched your search

+2 -2
Переглянути файл
@@ -357,8 +357,8 @@ export function nodeMenu(
},
{ kind: "separator" as const },
]),
// Under the modal interface the node itself, like double-click, in the front window.
vcsDiffInFront() && opts?.roots && first
// The node itself, like double-click: under Staged or Unstaged its side of the index.
opts?.roots && first
? {
label: "Show Diff",
icon: "diff",
+6 -2
Переглянути файл
@@ -294,10 +294,14 @@ describe("Changes tree diffs follow the commit interface setting (#1863)", () =>
expect(openFile).not.toHaveBeenCalled();
});
it("keeps the Show Diff action item with the non-modal interface", () => {
// The row's own diff (under Staged or Unstaged, its side of the index), in an editor tab.
it("opens the node's diff in an editor tab with the non-modal interface", async () => {
modal(false);
const menu = nodeMenu([node], ["/p"], { roots: [node] });
expect(menu).toContainEqual({ kind: "action", action: "vcs.showDiff", arg: "/p/src/a.ts" });
const show = menu.find((m) => m.kind !== "separator" && "label" in m && m.label === "Show Diff");
(show as { run: () => void }).run();
await vi.waitFor(() => expect(openInput).toHaveBeenCalledTimes(1));
expect(openDiffDialog).not.toHaveBeenCalled();
});
});
+24
Переглянути файл
@@ -18,6 +18,7 @@ import { useChangelists } from "../changelists";
import { useCommit } from "../commitStore";
import { inclusionChecks, isCommitAll, stagingChecks } from "../staging";
import { useVcs } from "../store";
import { provideEditorService } from "@/workbench/contributions";
const file = (rel: string, staged: FileStatus["staged"], unstaged: FileStatus["unstaged"]): FileStatus => ({
path: `/p/${rel}`,
@@ -130,6 +131,29 @@ describe("staging operations of the tree's nodes", () => {
]).toEqual([true, false]);
});
it("shows a row's side of the index from Show Diff: HEAD ↔ Index under Staged, Index ↔ working copy under Unstaged", async () => {
useSettings(true);
const openInput = vi.fn(async () => undefined);
provideEditorService({ openInput } as never);
const show = (node: (typeof roots)[number]) => {
const menu = nodeMenu([node], [], { roots });
(menu.find((m) => "label" in m && m.label === "Show Diff") as { run: () => void }).run();
};
const sides = () => {
const data = (openInput.mock.calls.at(-1) as unknown as [{ data: { left: unknown; right: unknown } }])[0].data;
return [data.left, data.right];
};
show(group("staged").children!.find((n) => n.label === "Partial.kt")!);
await vi.waitFor(() => expect(openInput).toHaveBeenCalledTimes(1));
expect(sides()).toEqual([
{ type: "rev", rev: "HEAD" },
{ type: "rev", rev: ":0", label: "Index" },
]);
show(group("unstaged").children!.find((n) => n.label === "Partial.kt")!);
await vi.waitFor(() => expect(openInput).toHaveBeenCalledTimes(2));
expect(sides()).toEqual([{ type: "rev", rev: ":0", label: "Index" }, { type: "worktree" }]);
});
it("has no Commit File…: a commit takes the whole index", () => {
useSettings(true);
const labels = (items: MenuItem[]) => items.map((i) => ("label" in i ? i.label : null));
+10 -5
Переглянути файл
@@ -60,6 +60,7 @@ import {
showWorktrees,
} from "./gitMenuDialogs";
import { currentRepo, refreshNow, repoName, repoOf, statusOf, useVcs } from "./store";
import { stagingAreaOn } from "./staging";
import { showSyncCommitsForCurrent } from "./SyncCommitsPopup";
import { tx } from "@/platform/i18n";
@@ -433,21 +434,24 @@ export function registerVcsActions(): () => void {
}
if (await showDirectoryWorkingDiff(paths)) return;
const state = useVcs.getState();
// The tree the Commit tool window shows: with the staging area, Staged / Unstaged and no lists.
const staging = stagingAreaOn();
const tree = buildChangeTree(
state.status,
state.root ?? "",
useCommit.getState().groupByDir,
useChangelists.getState().state,
staging ? undefined : useChangelists.getState().state,
state.roots,
useCommit.getState().groupByStaging,
useCommit.getState().groupByStaging || staging,
undefined,
useCommit.getState().groupByRepo,
useCommit.getState().showUnversionedSeparately,
);
// The selected rows while the tree has focus: a file under Staged or Unstaged diffs that side.
const targets = showDiffTargets(tree, paths, !argPaths(arg)?.length && commitWindowFocused());
// The modal interface has one front diff window (#1863): a file with its group
// as the F7 chain, or several selected files as the chain.
if (isModalCommit()) {
const targets = showDiffTargets(tree, paths, !argPaths(arg)?.length && commitWindowFocused());
const [first] = targets;
const data =
targets.length > 1
@@ -461,8 +465,9 @@ export function registerVcsActions(): () => void {
await openVcsDiff({ ...data, line });
return;
}
for (const path of paths.slice(0, 5)) {
await openDiff({ ...groupDiffData(tree, path), line }, { preview: paths.length === 1 });
for (const target of targets.slice(0, 5)) {
const data = typeof target === "string" ? groupDiffData(tree, target) : changeNodeDiffData(tree, target);
await openDiff({ ...data, line }, { preview: targets.length === 1 });
}
},
},