дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-27 13:06:07 +02:00
fix(vcs): group Commit changes menu actions by workflow
Цей коміт міститься в:
1 джерело
444c315d57
коміт
b221bf02e3
2 files changed
+112
-73
No files matched your search
@@ -334,32 +334,92 @@ export function nodeMenu(
|
||||
const untracked = files.filter((f) => f.unstaged === "untracked");
|
||||
const toIgnore = ignoreTargets(nodes, repos);
|
||||
const conflicted = files.filter((f) => f.unstaged === "conflicted");
|
||||
const items: MenuItem[] = [
|
||||
...(conflicted.length
|
||||
const staging = stagingAreaOn();
|
||||
const rollback: MenuItem = { kind: "action", action: "vcs.rollback", arg: paths, label: "Rollback…" };
|
||||
const stash: MenuItem = { kind: "action", action: "vcs.stashSelected", arg: paths, disabled: !paths.length };
|
||||
const stageActions: MenuItem[] = [
|
||||
{
|
||||
label: "Stage",
|
||||
icon: "plus",
|
||||
// Under Staged Changes, a partially staged file only offers Unstage.
|
||||
disabled: !files.some((f) => f.unstaged) || nodes.every((n) => n.group === "staged"),
|
||||
run: () => void runOp(tx`Stage ${paths.length} files`, () => call(commands.vcsStage(paths))),
|
||||
},
|
||||
{
|
||||
label: "Unstage",
|
||||
icon: "minus",
|
||||
disabled: !files.some((f) => f.staged) || nodes.every((n) => n.group === "unstaged" || n.group === "unversioned"),
|
||||
run: () => void runOp(tx`Unstage ${paths.length} files`, () => call(commands.vcsUnstage(paths))),
|
||||
},
|
||||
];
|
||||
const fileActions: MenuItem[] = [
|
||||
...(untracked.length
|
||||
? [{ kind: "action" as const, action: "vcs.addToVcs", arg: untracked.map((f) => f.path) }]
|
||||
: []),
|
||||
...(deletable.length
|
||||
? [
|
||||
{
|
||||
label: "Accept Yours",
|
||||
run: () => void Promise.all(conflicted.map((f) => acceptSide(f, "ours"))).then(() => refreshNow()),
|
||||
label: "Delete…",
|
||||
icon: "trash",
|
||||
shortcut: formatBinding(isMacHost() ? "Backspace" : "Delete"),
|
||||
run: () => void deleteFiles(deletable),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(toIgnore.length
|
||||
? [
|
||||
{
|
||||
label: "Add to .gitignore",
|
||||
submenu: [
|
||||
{ kind: "action" as const, action: "vcs.ignoreShared", arg: toIgnore, label: ".gitignore" },
|
||||
{ kind: "action" as const, action: "vcs.ignoreLocal", arg: toIgnore, label: ".git/info/exclude" },
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
// The staging menu operates on the index. A change list can commit or move individual files.
|
||||
const primary: MenuItem[] = staging
|
||||
? [...stageActions, stash, rollback, ...fileActions]
|
||||
: [
|
||||
{
|
||||
label: "Commit File…",
|
||||
icon: "commit",
|
||||
disabled: !files.some((f) => groupOf(f) === "changes"),
|
||||
run: () => commitFiles(paths),
|
||||
},
|
||||
rollback,
|
||||
...(nodes.some((n) => n.changelist)
|
||||
? [
|
||||
{
|
||||
kind: "action" as const,
|
||||
action: "vcs.changelist.move",
|
||||
arg: paths,
|
||||
label: "Move to Another Changelist…",
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
const contributed = menuGroupItems("changes", {
|
||||
paths: files.filter(onDisk).map((f) => stripSlash(f.path)),
|
||||
});
|
||||
return [
|
||||
...(conflicted.length
|
||||
? [
|
||||
{ kind: "action" as const, action: "vcs.resolveConflicts", label: "Resolve Conflicts…" },
|
||||
{
|
||||
label: "Accept Theirs",
|
||||
run: () => void Promise.all(conflicted.map((f) => acceptSide(f, "theirs"))).then(() => refreshNow()),
|
||||
},
|
||||
{
|
||||
label: "Accept Yours",
|
||||
run: () => void Promise.all(conflicted.map((f) => acceptSide(f, "ours"))).then(() => refreshNow()),
|
||||
},
|
||||
{ kind: "separator" as const },
|
||||
]
|
||||
: []),
|
||||
// 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 },
|
||||
]),
|
||||
...primary,
|
||||
{ kind: "separator" },
|
||||
// The node itself, like double-click: under Staged or Unstaged its side of the index.
|
||||
opts?.roots && first
|
||||
? {
|
||||
@@ -383,57 +443,14 @@ export function nodeMenu(
|
||||
disabled: !first?.path || first.kind === "deleted",
|
||||
run: () => first?.path && void editorService().openFile(first.path, { focus: true }),
|
||||
},
|
||||
{ label: "Copy Path", icon: "copy", run: () => copyChangePaths(nodes, "absolute") },
|
||||
{ label: "Copy File Name", icon: "copy", run: () => copyChangePaths(nodes, "name") },
|
||||
...(staging ? [] : [{ kind: "separator" as const }, ...fileActions, ...stageActions]),
|
||||
{ kind: "separator" },
|
||||
];
|
||||
if (conflicted.length) items.push({ kind: "action", action: "vcs.resolveConflicts", label: "Resolve Conflicts…" });
|
||||
items.push(
|
||||
{ kind: "action", action: "vcs.rollback", arg: paths, label: "Rollback…" },
|
||||
...(untracked.length
|
||||
? [{ kind: "action" as const, action: "vcs.addToVcs", arg: untracked.map((f) => f.path) }]
|
||||
: []),
|
||||
...(deletable.length
|
||||
? [
|
||||
{
|
||||
label: "Delete…",
|
||||
icon: "trash",
|
||||
shortcut: formatBinding(isMacHost() ? "Backspace" : "Delete"),
|
||||
run: () => void deleteFiles(deletable),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
// Both destinations, as in the project view's Git menu.
|
||||
...(toIgnore.length
|
||||
? [
|
||||
{
|
||||
label: "Add to .gitignore",
|
||||
submenu: [
|
||||
{ kind: "action" as const, action: "vcs.ignoreShared", arg: toIgnore, label: ".gitignore" },
|
||||
{ kind: "action" as const, action: "vcs.ignoreLocal", arg: toIgnore, label: ".git/info/exclude" },
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: "Stage",
|
||||
icon: "plus",
|
||||
// Under Staged Changes, a partially staged file only offers Unstage.
|
||||
disabled: !files.some((f) => f.unstaged) || nodes.every((n) => n.group === "staged"),
|
||||
run: () => void runOp(tx`Stage ${paths.length} files`, () => call(commands.vcsStage(paths))),
|
||||
},
|
||||
{
|
||||
label: "Unstage",
|
||||
icon: "minus",
|
||||
disabled: !files.some((f) => f.staged) || nodes.every((n) => n.group === "unstaged" || n.group === "unversioned"),
|
||||
run: () => void runOp(tx`Unstage ${paths.length} files`, () => call(commands.vcsUnstage(paths))),
|
||||
},
|
||||
{ kind: "separator" },
|
||||
...(nodes.some((n) => n.changelist)
|
||||
? [{ kind: "action" as const, action: "vcs.changelist.move", arg: paths, label: "Move to Another Changelist…" }]
|
||||
: []),
|
||||
{ kind: "action", action: "vcs.shelve", arg: paths },
|
||||
{ kind: "action", action: "vcs.createPatch", arg: paths },
|
||||
{ kind: "action", action: "vcs.stashSelected", arg: paths, disabled: !paths.length },
|
||||
{ label: "Copy as Patch to Clipboard", run: () => void copyChangesAsPatch(paths) },
|
||||
{ kind: "action", action: "vcs.shelve", arg: paths },
|
||||
...(staging ? [] : [stash]),
|
||||
{ kind: "separator" },
|
||||
{
|
||||
label: "Show History",
|
||||
@@ -443,15 +460,8 @@ export function nodeMenu(
|
||||
},
|
||||
{ kind: "action", action: "vcs.localHistory", arg: first?.path },
|
||||
{ kind: "action", action: "vcs.annotate", arg: first?.path },
|
||||
{ kind: "separator" },
|
||||
// Other features' groups (Deployment) for the files that exist.
|
||||
...menuGroupItems("changes", {
|
||||
paths: files.filter(onDisk).map((f) => stripSlash(f.path)),
|
||||
}),
|
||||
{ label: "Copy Path", icon: "copy", run: () => copyChangePaths(nodes, "absolute") },
|
||||
{ label: "Copy File Name", icon: "copy", run: () => copyChangePaths(nodes, "name") },
|
||||
);
|
||||
return items;
|
||||
...(contributed.length ? [{ kind: "separator" as const }, ...contributed] : []),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -162,6 +162,35 @@ describe("staging operations of the tree's nodes", () => {
|
||||
useSettings(false);
|
||||
expect(labels(nodeMenu([group("unstaged").children![0]!], []))).toContain("Commit File…");
|
||||
});
|
||||
|
||||
it.each([false, true])("groups the change menu for staging area = %s", (staging) => {
|
||||
useSettings(staging);
|
||||
const underUnstaged = group("unstaged").children!.find((n) => n.label === "Unstaged.kt")!;
|
||||
const node = staging ? underUnstaged : { ...underUnstaged, group: "changes" as const, changelist: "a" };
|
||||
const groups: string[][] = [[]];
|
||||
for (const item of nodeMenu([node], [], { roots })) {
|
||||
if (item.kind === "separator") groups.push([]);
|
||||
else groups.at(-1)!.push(item.kind === "action" ? item.action : item.label);
|
||||
}
|
||||
expect(groups[0]).toEqual(
|
||||
staging
|
||||
? ["Stage", "Unstage", "vcs.stashSelected", "vcs.rollback", "Delete…"]
|
||||
: ["Commit File…", "vcs.rollback", "vcs.changelist.move"],
|
||||
);
|
||||
expect(groups[1]).toEqual([
|
||||
"Show Diff",
|
||||
"vcs.showDiffInNewWindow",
|
||||
"Jump to Source",
|
||||
"Copy Path",
|
||||
"Copy File Name",
|
||||
]);
|
||||
expect(groups).toContainEqual([
|
||||
"vcs.createPatch",
|
||||
"Copy as Patch to Clipboard",
|
||||
"vcs.shelve",
|
||||
...(staging ? [] : ["vcs.stashSelected"]),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the Commit tool window with the staging area", () => {
|
||||
|
||||
Reference in new issue
Заблокувати користувача