diff --git a/docs/en/guide/vcs.mdx b/docs/en/guide/vcs.mdx
index 29928eba6..0e1a8026b 100644
--- a/docs/en/guide/vcs.mdx
+++ b/docs/en/guide/vcs.mdx
@@ -206,6 +206,7 @@ Limits: interactive rebase doesn't support ranges with merge commits, and **Undo
- **Shelve Changes…** lets you pick files and a name; the changes are then reverted.
- **Unshelve…** applies a shelf (or one file of it) with a three-way merge, into a changelist you choose.
+- **Shelve Silently** (`⇧⌘H` / `Ctrl+Shift+H`, also on the Changes toolbar) shelves the selected changes, or the active changelist, without the dialog: one shelf per changelist, named after it. **Unshelve Silently** (`⌥⌘U` / `Ctrl+Alt+U` in the Shelf) applies the selected shelf or file into the changelist with the shelf's name, else the active one.
- The **Shelf** tab shows shelves with diff, compare with local, patch export, rename and delete.
Turn on **Combine stashes and shelves in one tab** in the Git settings to show both in one tab.
diff --git a/docs/zh/guide/vcs.mdx b/docs/zh/guide/vcs.mdx
index c3942335c..ac55eac4a 100644
--- a/docs/zh/guide/vcs.mdx
+++ b/docs/zh/guide/vcs.mdx
@@ -204,6 +204,7 @@ Git 工具窗口的 **日志** 标签页显示提交图。
- **搁置更改…**:选择文件并命名,之后这些更改会被还原。
- **取消搁置…**:以三方合并的方式把搁置(或其中某个文件)应用到你选择的更改列表。
+- **静默搁置**(`⇧⌘H` / `Ctrl+Shift+H`,也在更改工具栏上)不弹对话框,直接搁置选中的更改(未选中时为活动更改列表):每个更改列表一个搁置,以列表名命名。**静默取消搁置**(在搁置中按 `⌥⌘U` / `Ctrl+Alt+U`)把选中的搁置或文件应用到与搁置同名的更改列表,没有则应用到活动更改列表。
- **搁置** 标签页列出所有搁置,支持查看差异、与本地比较、导出补丁、重命名和删除。
在 Git 设置中打开 **在同一个标签页中合并显示贮藏和搁置**,两者会显示在同一个标签页里。
diff --git a/src/features/vcs/CommitView.tsx b/src/features/vcs/CommitView.tsx
index e3e6d16dc..71b5edcf4 100644
--- a/src/features/vcs/CommitView.tsx
+++ b/src/features/vcs/CommitView.tsx
@@ -772,6 +772,7 @@ export function ChangesTree({ mode }: { mode: "commit" | "local" | "dialog" }) {
{mode === "local" && }
{mode === "local" && }
+ {mode !== "dialog" && }
{mode !== "dialog" && }
({
patch: vi.fn(),
probe: vi.fn(),
unshelve: vi.fn(),
+ shelve: vi.fn(),
}));
vi.mock("../diffInput", async (original) => ({
...(await original()),
@@ -30,18 +31,32 @@ vi.mock("@/platform/ipc", async (original) => ({
fsProbe: mocks.probe,
vcsShelfPatch: mocks.patch,
vcsUnshelve: mocks.unshelve,
+ vcsShelve: mocks.shelve,
},
}));
-import { ShelfPanel, copyShelfPatch, shelfDiffs, shelfTarget, showShelfDiff, unshelve, useShelf } from "../shelf";
+import {
+ ShelfPanel,
+ copyShelfPatch,
+ shelfDiffs,
+ shelfTarget,
+ shelveSilently,
+ showShelfDiff,
+ unshelve,
+ unshelveSilently,
+ useShelf,
+} from "../shelf";
import { useCommit } from "../commitStore";
import { useVcs } from "../store";
import { useChangelists } from "../changelists";
import { VcsDialogHost } from "../dialogs";
import { ContextMenuHost } from "@/ui";
import { registerVcsActions } from "../actions";
+import { registerHistoryActions } from "../historyActions";
import { getAction, isActionKeyEnabled } from "@/platform/actions";
import { intellijWindows } from "@/platform/keymaps/intellij-windows";
import { intellijMacos } from "@/platform/keymaps/intellij-macos";
+import { useProject } from "@/platform/project";
+import { setContext } from "@/platform/context";
const entry: ShelvedChangeList = {
id: "work",
@@ -255,3 +270,154 @@ describe("shelf scope and diffs", () => {
expect(mocks.execute).toHaveBeenCalledWith("vcs.shelf.copyPatch", { id: "work", path: "a.txt" });
});
});
+
+describe("Shelve Silently / Unshelve Silently", () => {
+ const change = (path: string) => ({
+ path,
+ relPath: path,
+ staged: null,
+ unstaged: "modified" as const,
+ renamedFrom: null,
+ });
+ const lists = (files: Record = {}, active = "default") =>
+ useChangelists.setState({
+ loaded: false,
+ state: {
+ lists: [
+ { id: "default", name: "Changes", comment: "" },
+ { id: "work", name: "Work", comment: "" },
+ ],
+ active,
+ files,
+ },
+ });
+ beforeEach(() => {
+ mocks.ipc.mockReset().mockImplementation(async (value: unknown) => (await value) ?? []);
+ mocks.shelve.mockImplementation(async (name: string, paths: string[]) => ({
+ ...entry,
+ id: name,
+ name,
+ files: paths.map((path) => ({ path, kind: "modified", oldPath: null })),
+ }));
+ mocks.unshelve.mockResolvedValue({ applied: ["a.txt"], conflicts: [] });
+ useVcs.setState({
+ root: "/repo",
+ roots: ["/repo"],
+ available: true,
+ status: [change("/repo/a.txt"), change("/repo/b.txt"), change("/repo/c.txt")],
+ });
+ useProject.setState({ settings: {} });
+ });
+
+ it("shelves the selected changes without a dialog, one shelf per changelist named after it", async () => {
+ lists({ "b.txt": "work" });
+ render();
+ await act(() => shelveSilently(["/repo/a.txt", "/repo/b.txt"]));
+ expect(mocks.shelve.mock.calls).toEqual([
+ ["Changes", ["/repo/a.txt"]],
+ ["Work", ["/repo/b.txt"]],
+ ]);
+ expect(screen.queryByRole("dialog")).toBeNull();
+ });
+
+ it("shelves the active changelist's changes when nothing is selected", async () => {
+ lists({ "a.txt": "default", "b.txt": "work", "c.txt": "work" }, "work");
+ await shelveSilently();
+ expect(mocks.shelve.mock.calls).toEqual([["Work", ["/repo/b.txt", "/repo/c.txt"]]]);
+ });
+
+ it("names the shelf like the Shelve dialog when the project has one changelist", async () => {
+ useChangelists.setState({
+ loaded: false,
+ state: { lists: [{ id: "default", name: "Changes", comment: "" }], active: "default", files: {} },
+ });
+ await shelveSilently(["/repo/a.txt"]);
+ expect(mocks.shelve.mock.calls).toEqual([["Uncommitted changes", ["/repo/a.txt"]]]);
+ });
+
+ it("shelves nothing when there are no changes", async () => {
+ lists();
+ useVcs.setState({ status: [] });
+ await shelveSilently();
+ await shelveSilently(["/repo/missing.txt"]);
+ expect(mocks.shelve).not.toHaveBeenCalled();
+ });
+
+ it("stops after a shelf fails so later changelists stay in the working tree", async () => {
+ lists({ "b.txt": "work" });
+ mocks.shelve.mockRejectedValueOnce(new Error("disk full"));
+ await shelveSilently(["/repo/a.txt", "/repo/b.txt"]);
+ expect(mocks.shelve).toHaveBeenCalledTimes(1);
+ });
+
+ it("ignores the Changes tab's selection while another Commit tab is shown", async () => {
+ lists();
+ const off = registerHistoryActions();
+ setContext("activeToolWindow", "commit");
+ useCommit.setState({ tab: "stashes", selection: ["/repo/b.txt"] });
+ try {
+ await getAction("vcs.shelveSilently")!.run({ ctx: {} });
+ expect(mocks.shelve).not.toHaveBeenCalled();
+ useCommit.setState({ tab: "changes" });
+ await getAction("vcs.shelveSilently")!.run({ ctx: {} });
+ expect(mocks.shelve.mock.calls).toEqual([["Changes", ["/repo/b.txt"]]]);
+ } finally {
+ off();
+ setContext("activeToolWindow", null);
+ useCommit.setState({ tab: "changes", selection: [] });
+ }
+ });
+
+ it("does nothing for a shelf without files", async () => {
+ lists();
+ await unshelveSilently({ ...entry, files: [] });
+ expect(mocks.unshelve).not.toHaveBeenCalled();
+ });
+
+ it("unshelves into the changelist named like the shelf, without a dialog", async () => {
+ lists();
+ render();
+ await act(() => unshelveSilently(entry));
+ expect(mocks.unshelve).toHaveBeenCalledWith("work", false, null);
+ expect(screen.queryByRole("dialog")).toBeNull();
+ expect(useChangelists.getState().state.files).toEqual({ "a.txt": "work" });
+ });
+
+ it("unshelves into the active changelist when no changelist has the shelf's name", async () => {
+ lists({}, "default");
+ await unshelveSilently({ ...entry, name: "Experiment" });
+ expect(useChangelists.getState().state.files).toEqual({ "a.txt": "default" });
+ });
+
+ it("unshelves only the selected file and follows the remove-applied setting", async () => {
+ lists();
+ useProject.setState({ settings: { vcs: { shelf: { removeApplied: true } } } });
+ await unshelveSilently(entry, "b.txt");
+ expect(mocks.unshelve.mock.calls).toEqual([["work", true, "b.txt"]]);
+ });
+
+ it("binds IDEA's shortcuts to the Commit tool window and the focused Shelf", async () => {
+ const off = registerHistoryActions();
+ try {
+ const shelve = getAction("vcs.shelveSilently")!;
+ const unshelveAction = getAction("vcs.unshelveSilently")!;
+ expect(intellijWindows[shelve.id]).toEqual(["Ctrl+Shift+H"]);
+ expect(intellijMacos[shelve.id]).toEqual(["Meta+Shift+H"]);
+ expect(intellijWindows[unshelveAction.id]).toEqual(["Ctrl+Alt+U"]);
+ expect(intellijMacos[unshelveAction.id]).toEqual(["Meta+Alt+U"]);
+ expect(isActionKeyEnabled(shelve, { vcsAvailable: true, activeToolWindow: "commit" })).toBe(true);
+ expect(isActionKeyEnabled(shelve, { vcsAvailable: true, activeToolWindow: "git" })).toBe(true);
+ expect(isActionKeyEnabled(shelve, { vcsAvailable: true, activeToolWindow: "commit", shelfFocus: true })).toBe(
+ false,
+ );
+ expect(isActionKeyEnabled(shelve, { vcsAvailable: true, editorTextFocus: true })).toBe(false);
+ expect(isActionKeyEnabled(unshelveAction, { vcsAvailable: true, shelfFocus: true })).toBe(true);
+ expect(isActionKeyEnabled(unshelveAction, { vcsAvailable: true, editorTextFocus: true })).toBe(false);
+ lists();
+ await unshelveAction.run({ ctx: {}, arg: { id: "work", path: "a.txt" } });
+ expect(mocks.unshelve).toHaveBeenCalledWith("work", false, "a.txt");
+ } finally {
+ off();
+ }
+ });
+});
diff --git a/src/features/vcs/historyActions.tsx b/src/features/vcs/historyActions.tsx
index 0344ed04f..aeae317c4 100644
--- a/src/features/vcs/historyActions.tsx
+++ b/src/features/vcs/historyActions.tsx
@@ -6,7 +6,7 @@ import { commitKey, commitRepo } from "./multiRoot";
* and patches (ids are bound in keymaps/intellij-macos.ts where IDEA binds them).
*/
import type { Commit } from "@/bindings";
-import { setContext } from "@/platform/context";
+import { getContext, setContext } from "@/platform/context";
import { call, commands } from "@/platform/ipc";
import { notifications, toolWindowService } from "@/workbench/contributions";
import { executeAction, registerActions, type Action } from "@/platform/actions";
@@ -57,10 +57,12 @@ import {
loadShelves,
renameShelf,
shelveChanges,
+ shelveSilently,
shelfTarget,
showShelf,
showShelfDiff,
unshelve,
+ unshelveSilently,
} from "./shelf";
import { currentRepo, focusRepo, useVcs } from "./store";
@@ -622,6 +624,20 @@ export function registerHistoryActions(): () => void {
when: VCS,
run: ({ arg }) => shelveChanges(changePaths(arg)),
},
+ {
+ id: "vcs.shelveSilently",
+ title: "Shelve Silently",
+ category: "Git",
+ icon: "shelve",
+ when: VCS,
+ keyWhen: "vcsAvailable && (activeToolWindow == commit || activeToolWindow == git) && !shelfFocus",
+ run: ({ arg }) => {
+ // The Changes tab's selection is stale while the Shelf or Stash tab is shown.
+ if (arg === undefined && getContext().activeToolWindow === "commit" && useCommit.getState().tab !== "changes")
+ return;
+ return shelveSilently(changePaths(arg));
+ },
+ },
{ id: "vcs.showShelf", title: "Show Shelf", category: "Git", icon: "shelve", when: VCS, run: showShelf },
{
id: "vcs.unshelve",
@@ -635,6 +651,19 @@ export function registerHistoryActions(): () => void {
else showShelf();
},
},
+ {
+ id: "vcs.unshelveSilently",
+ title: "Unshelve Silently",
+ category: "Git",
+ icon: "unshelve",
+ when: VCS,
+ keyWhen: "vcsAvailable && shelfFocus",
+ run: ({ arg }) => {
+ const target = shelfTarget(arg);
+ if (target) return unshelveSilently(target.entry, target.path);
+ showShelf();
+ },
+ },
{
id: "vcs.shelf.delete",
title: "Delete Shelved Changes",
diff --git a/src/features/vcs/shelf.tsx b/src/features/vcs/shelf.tsx
index b7661520c..1ed2f0547 100644
--- a/src/features/vcs/shelf.tsx
+++ b/src/features/vcs/shelf.tsx
@@ -6,7 +6,14 @@
import { writeClipboardText } from "@/platform/clipboard";
import { useEffect, useMemo, useState, type MouseEvent } from "react";
import { create } from "zustand";
-import type { ApplyOutcome, ChangedFile, FileStatus, ShelvedChangeList, ShelfDiffFile } from "@/bindings";
+import type {
+ ApplyOutcome,
+ ChangedFile,
+ ChangelistState,
+ FileStatus,
+ ShelvedChangeList,
+ ShelfDiffFile,
+} from "@/bindings";
import { setContext } from "@/platform/context";
import { shortcutLabel } from "@/platform/keymap";
import { openDiff, openVcsDiff, withChain, type DiffData } from "./diffInput";
@@ -88,6 +95,13 @@ export function defaultChangeFiles(paths?: readonly string[]): FileStatus[] {
);
}
+/** Name a shelf of `list`'s changes gets by default: the list's name once the project has several. */
+function shelfName(state: ChangelistState, list: string): string {
+ return state.lists.length > 1
+ ? (state.lists.find((l) => l.id === list) ?? activeList(state)).name
+ : "Uncommitted changes";
+}
+
export function shelveChanges(paths?: readonly string[]) {
const files = defaultChangeFiles(paths);
if (!files.length) {
@@ -95,8 +109,42 @@ export function shelveChanges(paths?: readonly string[]) {
return;
}
const state = useChangelists.getState().state;
- const name = state.lists.length > 1 ? activeList(state).name : "Uncommitted changes";
- openDialog((close) => );
+ openDialog((close) => );
+}
+
+/** IDEA's Shelve Silently: no dialog, one shelf per changelist the changes belong to, named after it. */
+export async function shelveSilently(paths?: readonly string[]) {
+ // Without a dialog to review the files, pick them after unsaved edits reach the disk.
+ await saveAll();
+ await refreshNow();
+ const files = defaultChangeFiles(paths);
+ if (!files.length) {
+ notifications().notify({ group: "vcs", level: "info", title: "No changes to shelve" });
+ return;
+ }
+ const state = useChangelists.getState().state;
+ const byList = new Map();
+ for (const f of files) {
+ const list = listOf(state, relOf(f.path));
+ const own = byList.get(list);
+ if (own) own.push(stripSlash(f.path));
+ else byList.set(list, [stripSlash(f.path)]);
+ }
+ for (const [list, chosen] of byList) if (!(await shelveFiles(shelfName(state, list), chosen))) return;
+}
+
+async function shelveFiles(name: string, paths: string[]): Promise {
+ const entry = await runOp(tx`Shelve changes “${name}”`, () => call(commands.vcsShelve(name, paths)));
+ if (!entry) return undefined;
+ void loadShelves().catch(() => undefined);
+ notifications().notify({
+ group: "vcs",
+ level: "info",
+ title: `Shelved ${entry.files.length} file${entry.files.length === 1 ? "" : "s"}`,
+ body: entry.name,
+ actions: [{ label: "Show Shelf", run: showShelf }],
+ });
+ return entry;
}
/** Files of `node` and everything below it. */
@@ -227,16 +275,7 @@ function ShelveDialog({
if (!chosen.length || !name.trim()) return;
onClose();
await saveAll();
- const entry = await runOp(tx`Shelve changes “${name.trim()}”`, () => call(commands.vcsShelve(name.trim(), chosen)));
- if (!entry) return;
- void loadShelves().catch(() => undefined);
- notifications().notify({
- group: "vcs",
- level: "info",
- title: `Shelved ${entry.files.length} file${entry.files.length === 1 ? "" : "s"}`,
- body: entry.name,
- actions: [{ label: "Show Shelf", run: showShelf }],
- });
+ await shelveFiles(name.trim(), chosen);
};
return (