fix(vcs): no Commit File… in the changes tree with the staging area (#4246)

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
This commit is contained in:
l0ng-ai
2026-11-18 18:39:57 +08:00
committed by GitHub
parent 706ce87cb7
commit 81aa9418aa
2 changed files with 22 additions and 8 deletions
+13 -8
View File
@@ -67,7 +67,7 @@ import {
import { applyStash, commitChanges, deleteFiles, dropStash, showUnstashDialog, stashChanges } from "./changeOps";
import { CommitOptionsPopup } from "./CommitOptions";
import { DEFAULT_LIST_NAME, useChangelists, withListDefaults } from "./changelists";
import { inclusionChecks, isCommitAll, useStagingArea } from "./staging";
import { inclusionChecks, isCommitAll, stagingAreaOn, useStagingArea } from "./staging";
import { addToChangelist, commitFiles } from "./changelistsUi";
import { acceptSide } from "./conflictsUi";
import { copyChangesAsPatch } from "./patches";
@@ -345,13 +345,18 @@ export function nodeMenu(
{ kind: "separator" as const },
]
: []),
{
label: "Commit File…",
icon: "commit",
disabled: !files.some((f) => groupOf(f) === "changes"),
run: () => commitFiles(paths),
},
{ kind: "separator" },
// With the staging area a commit takes the whole index: there is no committing one file.
...(stagingAreaOn()
? []
: [
{
label: "Commit File…",
icon: "commit" as const,
disabled: !files.some((f) => groupOf(f) === "changes"),
run: () => commitFiles(paths),
},
{ kind: "separator" as const },
]),
// Under the modal interface the node itself, like double-click, in the front window.
vcsDiffInFront() && opts?.roots && first
? {
@@ -129,6 +129,15 @@ describe("staging operations of the tree's nodes", () => {
enabled(nodeMenu([underUnstaged], []), "Unstage"),
]).toEqual([true, false]);
});
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));
for (const node of [group("staged").children![0]!, group("unstaged").children![0]!])
expect(labels(nodeMenu([node], []))).not.toContain("Commit File…");
useSettings(false);
expect(labels(nodeMenu([group("unstaged").children![0]!], []))).toContain("Commit File…");
});
});
describe("the Commit tool window with the staging area", () => {