feat(vcs): Copy Commit Subject action for the Git Log (#5761)

Copies the subject lines of the selected Git Log commits, one per line, newest first. Reached from Find Action or a keymap shortcut (no menu entry, no default shortcut); maps IDEA's Vcs.CopyCommitSubjectAction.

Closes #5760

Co-authored-by: mansur-akhmadi <[email protected]>
Цей коміт міститься в:
Mansur Akhmadiтаmansur-akhmadi authored and GitHub committed 2026-11-25 13:41:53 +08:00
1 джерело 1743aec533
коміт 465e4f80bc
10 files changed
+107 -2

No files matched your search

+1 -1
Переглянути файл
@@ -202,7 +202,7 @@ The **Log** tab of the Git tool window shows the commit graph.
- The details pane shows the changed files, the commit message, who committed it, which branches contain it and its signature.
- In the **Signature** column, hover over a badge to see the verification result, signer, and key fingerprint when available. After changing your verification keys or trust settings, click **Refresh** in the log toolbar to check again.
Right-click a commit for **Copy Revision Number** (`⌥⇧⌘C` / `Ctrl+Alt+Shift+C`), **Create Patch…**, **Cherry-Pick**, **Checkout Revision**, **Show Repository at Revision**, **Compare with Local**, **Reset Current Branch to Here…**, **Revert Commit**, **Undo Commit…**, **New Branch…**, **New Tag…**, **View in Browser** and more. With two commits selected, **Compare Versions** diffs them. With the commit list focused, `F2` edits the commit message, `⌥⌘N` / `Ctrl+Alt+N` creates a branch, `←` / `→` go to the child or parent commit, and `F3` / `F11` toggles a commit bookmark (`⌥F3` / `Ctrl+F11` with a mnemonic).
Right-click a commit for **Copy Revision Number** (`⌥⇧⌘C` / `Ctrl+Alt+Shift+C`), **Create Patch…**, **Cherry-Pick**, **Checkout Revision**, **Show Repository at Revision**, **Compare with Local**, **Reset Current Branch to Here…**, **Revert Commit**, **Undo Commit…**, **New Branch…**, **New Tag…**, **View in Browser** and more. With two commits selected, **Compare Versions** diffs them. With the commit list focused, `F2` edits the commit message, `⌥⌘N` / `Ctrl+Alt+N` creates a branch, `←` / `→` go to the child or parent commit, and `F3` / `F11` toggles a commit bookmark (`⌥F3` / `Ctrl+F11` with a mnemonic). **Copy Commit Subject**, run from **Find Action** or a shortcut you assign in **Settings › Keymap**, copies the subject lines of the selected commits, one per line.
In the changed-files pane, use **Apply Selected Changes** to bring only the selected files' changes into the working tree.
Use **Extract Selected Changes** on part of a commit to move those files' changes into a new commit immediately after it. The operation preserves the tip's tree, local edits, and staged changes. The success notification offers **Undo** while HEAD still points to the rewritten tip.
+1 -1
Переглянути файл
@@ -200,7 +200,7 @@ Git 工具窗口的 **日志** 标签页显示提交图。
- 详情面板显示变更文件、提交消息、提交者、包含该提交的分支以及签名。
- 将鼠标悬停在 **签名** 列的图标上,可查看验签结果,以及可用的签名者和密钥指纹。更改验签密钥或信任设置后,点击日志工具栏的 **刷新** 重新验签。
右键提交可以选择 **复制修订号**(`⌥⇧⌘C` / `Ctrl+Alt+Shift+C`)、**创建补丁…**、**拣选**、**签出修订**、**显示此修订版本的仓库**、**与本地比较**、**将当前分支重置到此处…**、**还原提交**、**撤消提交…**、**新建分支…**、**新建标签…**、**在浏览器中查看** 等。选中两个提交时,**比较版本** 会比较它们。提交列表获得焦点时,`F2` 编辑提交消息,`⌥⌘N` / `Ctrl+Alt+N` 新建分支,`←` / `→` 跳到子提交或父提交,`F3` / `F11` 切换提交书签(`⌥F3` / `Ctrl+F11` 带助记符)。
右键提交可以选择 **复制修订号**(`⌥⇧⌘C` / `Ctrl+Alt+Shift+C`)、**创建补丁…**、**拣选**、**签出修订**、**显示此修订版本的仓库**、**与本地比较**、**将当前分支重置到此处…**、**还原提交**、**撤消提交…**、**新建分支…**、**新建标签…**、**在浏览器中查看** 等。选中两个提交时,**比较版本** 会比较它们。提交列表获得焦点时,`F2` 编辑提交消息,`⌥⌘N` / `Ctrl+Alt+N` 新建分支,`←` / `→` 跳到子提交或父提交,`F3` / `F11` 切换提交书签(`⌥F3` / `Ctrl+F11` 带助记符)。从 **查找操作** 或在 **设置 › 按键映射** 中分配的快捷键执行 **复制提交主题**,会复制所选提交的主题行,每行一个。
### 改写历史
+90
Переглянути файл
@@ -0,0 +1,90 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { Commit } from "@/bindings";
import { executeAction, getAction } from "@/platform/actions";
import { setContext } from "@/platform/context";
import { IDEA_ACTIONS } from "@/platform/ideaActions";
import { useGitLog } from "../logStore";
import { useVcs } from "../store";
const mocks = vi.hoisted(() => ({ writeClipboardText: vi.fn(), notify: vi.fn() }));
vi.mock("@/platform/clipboard", async (importOriginal) => ({
...(await importOriginal<typeof import("@/platform/clipboard")>()),
writeClipboardText: mocks.writeClipboardText,
}));
vi.mock("@/workbench/contributions", async (importOriginal) => ({
...(await importOriginal<typeof import("@/workbench/contributions")>()),
notifications: () => ({ notify: mocks.notify }),
}));
import { registerHistoryActions } from "../historyActions";
const commit = (id: string, summary: string, message = summary): Commit => ({
id: id.repeat(40),
shortId: id.repeat(8),
parents: [],
author: "A",
email: "[email protected]",
timeMs: 0,
summary,
message,
refs: [],
});
const newer = commit("b", "Fix the parser", "Fix the parser\n\nThe body is not copied.");
const older = commit("a", "Add a parser");
const originalLog = useGitLog.getState();
const originalVcs = useVcs.getState();
let unregister: (() => void) | undefined;
beforeEach(() => {
mocks.writeClipboardText.mockReset();
mocks.notify.mockReset();
useGitLog.setState({ commits: [newer, older], selected: null, selection: [], shownLog: "log", logTabs: [] });
useVcs.setState({ root: "/repo", repo: "/repo", roots: ["/repo"], branchesLoaded: true });
setContext("vcsAvailable", true);
unregister = registerHistoryActions();
});
afterEach(() => {
unregister?.();
unregister = undefined;
useGitLog.setState(originalLog);
useVcs.setState(originalVcs);
setContext("vcsAvailable", false);
});
describe("Copy Commit Subject", () => {
it("is a Git Log action that IDEA's Vcs.CopyCommitSubjectAction maps to", () => {
expect(getAction("vcs.log.copyCommitSubject")).toMatchObject({
title: "Copy Commit Subject",
category: "Git Log",
});
expect(IDEA_ACTIONS["Vcs.CopyCommitSubjectAction"]).toBe("vcs.log.copyCommitSubject");
});
it("copies the subjects of the selected commits, one per line, newest first", async () => {
useGitLog.setState({ selected: older.id, selection: [older.id, newer.id] });
await executeAction("vcs.log.copyCommitSubject");
await vi.waitFor(() => expect(mocks.writeClipboardText).toHaveBeenCalledOnce());
expect(mocks.writeClipboardText).toHaveBeenCalledWith("Fix the parser\nAdd a parser");
});
it("copies the subject, not the message body", async () => {
useGitLog.setState({ selected: newer.id, selection: [newer.id] });
await executeAction("vcs.log.copyCommitSubject");
await vi.waitFor(() => expect(mocks.writeClipboardText).toHaveBeenCalledWith("Fix the parser"));
});
it("copies the commit it is given and works on read-only commits", async () => {
await executeAction("vcs.log.copyCommitSubject", { ...older, readOnly: true });
await vi.waitFor(() => expect(mocks.writeClipboardText).toHaveBeenCalledWith("Add a parser"));
});
it("copies nothing without a selected commit", async () => {
await executeAction("vcs.log.copyCommitSubject");
expect(mocks.writeClipboardText).not.toHaveBeenCalled();
expect(mocks.notify).toHaveBeenCalledWith(expect.objectContaining({ title: "Select a commit in the Git log" }));
});
});
+9
Переглянути файл
@@ -406,6 +406,15 @@ export function registerHistoryActions(): () => void {
keyWhen: IN_GIT_LOG,
run: withCommits((cs) => writeClipboardText(cs.map((c) => c.id).join(" ")), { allowReadOnly: true }),
},
{
id: "vcs.log.copyCommitSubject",
title: "Copy Commit Subject",
category: "Git Log",
icon: "copy",
when: "vcsAvailable || projectOpen || vcsLogFocus",
keyWhen: IN_GIT_LOG,
run: withCommits((cs) => writeClipboardText(cs.map((c) => c.summary).join("\n")), { allowReadOnly: true }),
},
{
id: "vcs.log.createPatch",
title: "Create Patch…",
+1
Переглянути файл
@@ -133,4 +133,5 @@ export const IDEA_ACTIONS: Readonly<Record<string, string>> = {
"Compare.SameVersion": "vcs.showDiff",
"ChangesView.ShelveSilently": "vcs.shelveSilently",
"ChangesView.UnshelveSilently": "vcs.unshelveSilently",
"Vcs.CopyCommitSubjectAction": "vcs.log.copyCommitSubject",
};
+1
Переглянути файл
@@ -356,6 +356,7 @@ export const intellijMacos: Record<string, string[]> = {
"vcs.unshelveSilently": ["Meta+Alt+U"],
"vcs.changelist.edit": ["F2", "Shift+F6"],
"vcs.log.copyRevision": ["Meta+Alt+Shift+C"],
"vcs.log.copyCommitSubject": [],
"vcs.log.goToRef": ["Meta+F"],
"vcs.log.editMessage": ["F2", "Shift+F6"],
"vcs.log.newBranch": ["Meta+Alt+N"],
+1
Переглянути файл
@@ -354,6 +354,7 @@ export const intellijWindows: Record<string, string[]> = {
"vcs.unshelveSilently": ["Ctrl+Alt+U"],
"vcs.changelist.edit": ["F2", "Shift+F6"],
"vcs.log.copyRevision": ["Ctrl+Alt+Shift+C"],
"vcs.log.copyCommitSubject": [],
"vcs.log.goToRef": ["Ctrl+F"],
"vcs.log.editMessage": ["F2", "Shift+F6"],
"vcs.log.newBranch": ["Ctrl+Alt+N"],
+1
Переглянути файл
@@ -365,6 +365,7 @@ export const vscodeMacos: Record<string, string[]> = {
"vcs.unshelveSilently": [],
"vcs.changelist.edit": [],
"vcs.log.copyRevision": [],
"vcs.log.copyCommitSubject": [],
"vcs.log.goToRef": [],
"vcs.log.editMessage": [],
"vcs.log.newBranch": [],
+1
Переглянути файл
@@ -1190,6 +1190,7 @@
"Copy": "複製",
"Copy / Paste Special": "複製/選擇性貼上",
"Copy All": "全部複製",
"Copy Commit Subject": "複製提交主題",
"Copy Configuration": "複製組態",
"Copy Container ID": "複製容器 ID",
"Copy Coordinates": "複製座標",
+1
Переглянути файл
@@ -1555,6 +1555,7 @@
"Copy / Paste Special": "复制/选择性粘贴",
"Copy All": "全部复制",
"Copy Command": "复制命令",
"Copy Commit Subject": "复制提交主题",
"Copy Configuration": "复制配置",
"Copy Container ID": "复制容器 ID",
"Copy Coordinates": "复制坐标",