From 04bea8718efed577c10a572363dac822191fe762 Mon Sep 17 00:00:00 2001 From: Muu Date: Mon, 30 Nov 2026 00:36:23 +0800 Subject: [PATCH] feat(vcs): refresh Git Log with the Refresh shortcut (#6862) Adds the Git Log Refresh action (Vcs.Log.Refresh) for Git Log and File History, bound to the Refresh shortcut (Ctrl+F5 on Windows/Linux, Cmd+R on macOS) and scoped to the log so other bindings keep the key elsewhere. The toolbar button and the action share one refresh path that keeps the current log while reloading, invalidates commit-detail caches for the visible repositories and is ignored while the log is already loading. Co-authored-by: muutot <92625353+muutot@users.noreply.github.com> --- e2e/logBranchRenameFollow.spec.ts | 33 +++++++ src/features/vcs/__tests__/logRefresh.test.ts | 94 +++++++++++++++++++ src/features/vcs/historyActions.tsx | 9 ++ src/features/vcs/log/FilterBar.tsx | 13 +-- src/features/vcs/logRefresh.ts | 11 +++ src/platform/ideaActions.ts | 1 + src/platform/keymaps/eclipse.test.ts | 2 + src/platform/keymaps/ideaParity.test.ts | 1 + src/platform/keymaps/intellij-macos.ts | 2 + src/platform/keymaps/intellij-windows.ts | 2 + src/platform/keymaps/vscode-macos.ts | 2 + 11 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 src/features/vcs/__tests__/logRefresh.test.ts create mode 100644 src/features/vcs/logRefresh.ts diff --git a/e2e/logBranchRenameFollow.spec.ts b/e2e/logBranchRenameFollow.spec.ts index 61c83e3d6..82a6e1ddb 100644 --- a/e2e/logBranchRenameFollow.spec.ts +++ b/e2e/logBranchRenameFollow.spec.ts @@ -112,6 +112,39 @@ async function openLogOnSd(page: Page) { await expect(page.getByRole("listbox", { name: "Commits" }).getByRole("option").first()).toBeVisible(); } +test("Refresh (Cmd+R) refreshes the visible Git Log and File History repositories", async ({ workbench: page }) => { + await openLogOnSd(page); + const commits = page.getByRole("listbox", { name: "Commits" }); + const first = commits.getByRole("option").first(); + const logCalls = await ipcCalls(page, "vcs_log"); + const signatureCalls = await ipcCalls(page, "vcs_invalidate_log_signatures"); + + await commits.focus(); + await page.keyboard.press("Meta+R"); + await expect.poll(async () => (await ipcCalls(page, "vcs_log")).length).toBeGreaterThan(logCalls.length); + await expect + .poll(async () => (await ipcCalls(page, "vcs_invalidate_log_signatures")).length) + .toBeGreaterThan(signatureCalls.length); + await expect(first).toBeVisible(); + + await page.getByRole("treeitem", { name: "README.md", exact: true }).click({ button: "right" }); + await page.getByRole("menuitem", { name: "Git", exact: true }).hover(); + await page.getByRole("menuitem", { name: "Show History", exact: true }).click(); + const historyTab = page.getByRole("tablist", { name: "Git" }).getByRole("tab", { name: /History: README.md/ }); + await expect(historyTab).toHaveAttribute("aria-selected", "true"); + await expect(first).toBeVisible(); + const historyLogCalls = (await ipcCalls(page, "vcs_log")).length; + const historySignatureCalls = (await ipcCalls(page, "vcs_invalidate_log_signatures")).length; + + await commits.focus(); + await page.keyboard.press("Meta+R"); + await expect.poll(async () => (await ipcCalls(page, "vcs_log")).length).toBeGreaterThan(historyLogCalls); + await expect + .poll(async () => (await ipcCalls(page, "vcs_invalidate_log_signatures")).length) + .toBeGreaterThan(historySignatureCalls); + await expect(first).toBeVisible(); +}); + test("Ctrl+L toggles focus between Git Log filters and commits, including File History", async ({ workbench: page, }) => { diff --git a/src/features/vcs/__tests__/logRefresh.test.ts b/src/features/vcs/__tests__/logRefresh.test.ts new file mode 100644 index 000000000..bb89b27c2 --- /dev/null +++ b/src/features/vcs/__tests__/logRefresh.test.ts @@ -0,0 +1,94 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { executeAction, getAction, isActionKeyEnabled } from "@/platform/actions"; +import { getContext, setContext } from "@/platform/context"; +import { IDEA_ACTIONS } from "@/platform/ideaActions"; +import { intellijMacos } from "@/platform/keymaps/intellij-macos"; +import { intellijWindows } from "@/platform/keymaps/intellij-windows"; +import { registerHistoryActions } from "../historyActions"; +import { refreshLogView } from "../logRefresh"; +import { useGitLog } from "../logStore"; +import { useVcs } from "../store"; + +const mocks = vi.hoisted(() => ({ loading: false, reloadLog: vi.fn(), refreshLogDetails: vi.fn() })); + +vi.mock("../logStore", async (importOriginal) => ({ + ...(await importOriginal()), + reloadLog: mocks.reloadLog, + logState: () => ({ loading: mocks.loading }), +})); +vi.mock("../logDetails", async (importOriginal) => ({ + ...(await importOriginal()), + refreshLogDetails: mocks.refreshLogDetails, +})); + +const originalLog = useGitLog.getState(); +const originalVcs = useVcs.getState(); +const originalContext = getContext(); +let unregister: (() => void) | undefined; + +beforeEach(() => { + mocks.loading = false; + mocks.reloadLog.mockReset(); + mocks.refreshLogDetails.mockReset(); + useGitLog.setState({ shownLog: "log", logTabs: [] }); + useVcs.setState({ roots: ["/repo-a", "/repo-b"] }); + setContext("vcsAvailable", true); + setContext("activeToolWindow", "git"); + unregister = registerHistoryActions(); +}); + +afterEach(() => { + unregister?.(); + unregister = undefined; + useGitLog.setState(originalLog); + useVcs.setState(originalVcs); + setContext("vcsAvailable", originalContext.vcsAvailable); + setContext("activeToolWindow", originalContext.activeToolWindow); +}); + +describe("Git Log refresh", () => { + it("maps IDEA's action and scopes Refresh's shortcut to Git Log or File History", async () => { + const action = getAction("vcs.log.refresh")!; + expect(IDEA_ACTIONS["Vcs.Log.Refresh"]).toBe("vcs.log.refresh"); + expect(intellijWindows[action.id]).toEqual(["Ctrl+F5"]); + expect(intellijMacos[action.id]).toEqual(["Meta+R"]); + expect(isActionKeyEnabled(action, { vcsAvailable: true, activeToolWindow: "git" })).toBe(true); + expect(isActionKeyEnabled(action, { vcsAvailable: true, activeToolWindow: "editor", vcsLogFocus: true })).toBe( + true, + ); + expect( + isActionKeyEnabled(action, { vcsAvailable: true, activeToolWindow: "project", projectViewFocus: true }), + ).toBe(false); + + await executeAction("vcs.log.refresh"); + expect(mocks.reloadLog).toHaveBeenCalledWith({ preserve: true }, "log"); + expect(mocks.refreshLogDetails).toHaveBeenCalledWith(["/repo-a", "/repo-b"]); + }); + + it("refreshes only the visible tab's repositories", () => { + useGitLog.setState({ + shownLog: "history", + logTabs: [ + { + id: "history", + kind: "history", + target: "/repo-a/src/a.ts", + repo: "/repo-a", + repositories: ["/repo-a", "/repo-b"], + location: "toolWindow", + readOnly: false, + }, + ], + }); + refreshLogView(); + expect(mocks.reloadLog).toHaveBeenCalledWith({ preserve: true }, "history"); + expect(mocks.refreshLogDetails).toHaveBeenCalledWith(["/repo-a", "/repo-b"]); + }); + + it("ignores refresh while the visible log is already loading", () => { + mocks.loading = true; + refreshLogView(); + expect(mocks.reloadLog).not.toHaveBeenCalled(); + expect(mocks.refreshLogDetails).not.toHaveBeenCalled(); + }); +}); diff --git a/src/features/vcs/historyActions.tsx b/src/features/vcs/historyActions.tsx index 99363748d..2bae54679 100644 --- a/src/features/vcs/historyActions.tsx +++ b/src/features/vcs/historyActions.tsx @@ -83,6 +83,7 @@ import { unshelveSilently, } from "./shelf"; import { currentRepo, currentRepoRoot, focusRepo, useVcs } from "./store"; +import { refreshLogView } from "./logRefresh"; import type { PatchDiffRequest } from "./patchDiff"; const VCS = "vcsAvailable"; @@ -405,6 +406,14 @@ export function registerHistoryActions(): () => void { }, }, + { + id: "vcs.log.refresh", + title: "Refresh", + category: "Git Log", + when: "vcsAvailable || projectOpen || vcsLogFocus", + keyWhen: IN_GIT_LOG, + run: () => refreshLogView(), + }, { id: "vcs.log.focusTextFilter", title: "Focus Text Filter", diff --git a/src/features/vcs/log/FilterBar.tsx b/src/features/vcs/log/FilterBar.tsx index 5e8d99c99..f33dae459 100644 --- a/src/features/vcs/log/FilterBar.tsx +++ b/src/features/vcs/log/FilterBar.tsx @@ -10,7 +10,7 @@ import { BranchFilterPopup } from "../BranchFilterPopup"; import { chooseDateRange, chooseMany } from "../dialogs"; import styles from "../GitLog.module.css"; import { LogIdContext } from "../logContext"; -import { refreshLogDetails } from "../logDetails"; +import { refreshLogView } from "../logRefresh"; import { useLogOptions, type LogOptions } from "../logOptions"; import { ME, @@ -19,7 +19,6 @@ import { openLogTab, recentFilterValues, recentLogFilters, - reloadLog, recentFilterKey, setLogBranches, setLogFilters, @@ -528,15 +527,7 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) { ) } /> - { - void reloadLog({ preserve: true }, scope ?? undefined); - void refreshLogDetails(repositories); - }} - /> + refreshLogView(scope ?? undefined)} /> {!readOnly && !fileHistory && ( )} diff --git a/src/features/vcs/logRefresh.ts b/src/features/vcs/logRefresh.ts new file mode 100644 index 000000000..c0c5acc33 --- /dev/null +++ b/src/features/vcs/logRefresh.ts @@ -0,0 +1,11 @@ +import { refreshLogDetails } from "./logDetails"; +import { logState, reloadLog, useGitLog } from "./logStore"; +import { useVcs } from "./store"; + +export function refreshLogView(id = useGitLog.getState().shownLog) { + if (logState(id).loading) return; + const tab = useGitLog.getState().logTabs.find((entry) => entry.id === id); + const roots = tab?.repositories?.length ? tab.repositories : tab?.repo ? [tab.repo] : useVcs.getState().roots; + void reloadLog({ preserve: true }, id); + void refreshLogDetails(roots); +} diff --git a/src/platform/ideaActions.ts b/src/platform/ideaActions.ts index 9784b5d3a..52daf0982 100644 --- a/src/platform/ideaActions.ts +++ b/src/platform/ideaActions.ts @@ -185,5 +185,6 @@ export const IDEA_ACTIONS: Readonly> = { ShowUmlDiagram: "db.showDiagram", ShowUmlDiagramPopup: "db.showDiagramPopup", "Vcs.CopyCommitSubjectAction": "vcs.log.copyCommitSubject", + "Vcs.Log.Refresh": "vcs.log.refresh", "Vcs.Log.FocusTextFilter": "vcs.log.focusTextFilter", }; diff --git a/src/platform/keymaps/eclipse.test.ts b/src/platform/keymaps/eclipse.test.ts index a88596390..f05854bb6 100644 --- a/src/platform/keymaps/eclipse.test.ts +++ b/src/platform/keymaps/eclipse.test.ts @@ -70,6 +70,7 @@ const shared = [ "github.refresh", "github.pullRequest.refresh", "github.pullRequest.timeline.refresh", + "vcs.log.refresh", ], [ "debug.runToCursor", @@ -77,6 +78,7 @@ const shared = [ "github.refresh", "github.pullRequest.refresh", "github.pullRequest.timeline.refresh", + "vcs.log.refresh", ], ["editor.increaseFontSize", "image.zoomIn"], ["editor.decreaseFontSize", "image.zoomOut"], diff --git a/src/platform/keymaps/ideaParity.test.ts b/src/platform/keymaps/ideaParity.test.ts index 5c9338f0c..a2f9f2715 100644 --- a/src/platform/keymaps/ideaParity.test.ts +++ b/src/platform/keymaps/ideaParity.test.ts @@ -116,6 +116,7 @@ describe("IDEA keymap parity", () => { ["find.recentUsages", [], []], // Vcs.Log.GoToRef: Find in the Git Log table. ["vcs.log.goToRef", ["Meta+F"], ["Ctrl+F"]], + ["vcs.log.refresh", ["Meta+R"], ["Ctrl+F5"]], ["vcs.log.focusTextFilter", ["Ctrl+L"], ["Ctrl+L"]], // Back / Forward also carry the mouse side buttons (``). ["editor.codeBlockStartWithSelection", ["Meta+Alt+Shift+["], ["Ctrl+Shift+["]], diff --git a/src/platform/keymaps/intellij-macos.ts b/src/platform/keymaps/intellij-macos.ts index 128295637..db22d9730 100644 --- a/src/platform/keymaps/intellij-macos.ts +++ b/src/platform/keymaps/intellij-macos.ts @@ -499,6 +499,8 @@ export const intellijMacos: Record = { "github.refresh": ["Meta+R"], "github.pullRequest.refresh": ["Meta+R"], "github.pullRequest.timeline.refresh": ["Meta+R"], + // Git Log / File History (IDEA's Vcs.Log.Refresh takes Refresh's shortcut). + "vcs.log.refresh": ["Meta+R"], "github.pullRequest.toggleViewed": ["Meta+Shift+S"], "db.properties": ["Shift+Enter"], "db.refresh": ["Meta+R"], diff --git a/src/platform/keymaps/intellij-windows.ts b/src/platform/keymaps/intellij-windows.ts index fb3ee8732..c6ae58f34 100644 --- a/src/platform/keymaps/intellij-windows.ts +++ b/src/platform/keymaps/intellij-windows.ts @@ -497,6 +497,8 @@ export const intellijWindows: Record = { "github.refresh": ["Ctrl+F5"], "github.pullRequest.refresh": ["Ctrl+F5"], "github.pullRequest.timeline.refresh": ["Ctrl+F5"], + // Git Log / File History (IDEA's Vcs.Log.Refresh takes Refresh's shortcut). + "vcs.log.refresh": ["Ctrl+F5"], "github.pullRequest.toggleViewed": ["Ctrl+Shift+S"], "db.properties": ["Shift+Enter"], "db.refresh": ["Ctrl+F5"], diff --git a/src/platform/keymaps/vscode-macos.ts b/src/platform/keymaps/vscode-macos.ts index 47c91f7e7..dc24b272b 100644 --- a/src/platform/keymaps/vscode-macos.ts +++ b/src/platform/keymaps/vscode-macos.ts @@ -412,6 +412,8 @@ export const vscodeMacos: Record = { "vcs.unshelveSilently": [], "vcs.changelist.edit": [], "vcs.log.copyRevision": [], + "vcs.log.refresh": [], + "vcs.log.focusTextFilter": [], "vcs.log.copyCommitSubject": [], "vcs.log.goToRef": [], "vcs.log.editMessage": [],