Compare commits

..
Author SHA1 Message Date
l0ng-ai 7540ef29b7 fix(vcs): no Commit File… in the changes tree with the staging area
With the staging area the commit takes the whole index, so Commit File… on a
staged file only focused the message and committed every staged file. The
item is left out of the changes tree's menu while the staging area is on, as
the staging tree has no per-file commit.

Fixes #4153
2026-11-18 18:39:44 +08:00
4 changed files with 9 additions and 42 deletions

No files matched your search

+2 -2
View File
@@ -357,8 +357,8 @@ export function nodeMenu(
},
{ kind: "separator" as const },
]),
// The node itself, like double-click: under Staged or Unstaged its side of the index.
opts?.roots && first
// Under the modal interface the node itself, like double-click, in the front window.
vcsDiffInFront() && opts?.roots && first
? {
label: "Show Diff",
icon: "diff",
@@ -294,14 +294,10 @@ describe("Changes tree diffs follow the commit interface setting (#1863)", () =>
expect(openFile).not.toHaveBeenCalled();
});
// 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 () => {
it("keeps the Show Diff action item with the non-modal interface", () => {
modal(false);
const menu = nodeMenu([node], ["/p"], { roots: [node] });
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();
expect(menu).toContainEqual({ kind: "action", action: "vcs.showDiff", arg: "/p/src/a.ts" });
});
});
@@ -18,7 +18,6 @@ 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}`,
@@ -131,29 +130,6 @@ 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));
+5 -10
View File
@@ -60,7 +60,6 @@ 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";
@@ -434,24 +433,21 @@ 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,
staging ? undefined : useChangelists.getState().state,
useChangelists.getState().state,
state.roots,
useCommit.getState().groupByStaging || staging,
useCommit.getState().groupByStaging,
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
@@ -465,9 +461,8 @@ export function registerVcsActions(): () => void {
await openVcsDiff({ ...data, line });
return;
}
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 });
for (const path of paths.slice(0, 5)) {
await openDiff({ ...groupDiffData(tree, path), line }, { preview: paths.length === 1 });
}
},
},