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 <[email protected]>
Цей коміт міститься в:
Muuтаmuutot authored and GitHub committed 2026-11-30 00:36:23 +08:00
1 джерело 7f32d04b19
коміт 04bea8718e
11 files changed
+159 -11

No files matched your search

+33
Переглянути файл
@@ -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,
}) => {
+94
Переглянути файл
@@ -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<typeof import("../logStore")>()),
reloadLog: mocks.reloadLog,
logState: () => ({ loading: mocks.loading }),
}));
vi.mock("../logDetails", async (importOriginal) => ({
...(await importOriginal<typeof import("../logDetails")>()),
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();
});
});
+9
Переглянути файл
@@ -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",
+2 -11
Переглянути файл
@@ -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 }) {
)
}
/>
<IconButton
icon="refresh"
title="Refresh"
size="small"
onClick={() => {
void reloadLog({ preserve: true }, scope ?? undefined);
void refreshLogDetails(repositories);
}}
/>
<IconButton icon="refresh" title="Refresh" size="small" onClick={() => refreshLogView(scope ?? undefined)} />
{!readOnly && !fileHistory && (
<IconButton icon="cherry-pick" size="small" action="vcs.log.cherryPick" disabled={!canCherryPick} />
)}
+11
Переглянути файл
@@ -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);
}
+1
Переглянути файл
@@ -185,5 +185,6 @@ export const IDEA_ACTIONS: Readonly<Record<string, string>> = {
ShowUmlDiagram: "db.showDiagram",
ShowUmlDiagramPopup: "db.showDiagramPopup",
"Vcs.CopyCommitSubjectAction": "vcs.log.copyCommitSubject",
"Vcs.Log.Refresh": "vcs.log.refresh",
"Vcs.Log.FocusTextFilter": "vcs.log.focusTextFilter",
};
+2
Переглянути файл
@@ -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"],
+1
Переглянути файл
@@ -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 (`<mouse-shortcut keystroke="button4"/>`).
["editor.codeBlockStartWithSelection", ["Meta+Alt+Shift+["], ["Ctrl+Shift+["]],
+2
Переглянути файл
@@ -499,6 +499,8 @@ export const intellijMacos: Record<string, string[]> = {
"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"],
+2
Переглянути файл
@@ -497,6 +497,8 @@ export const intellijWindows: Record<string, string[]> = {
"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"],
+2
Переглянути файл
@@ -412,6 +412,8 @@ export const vscodeMacos: Record<string, string[]> = {
"vcs.unshelveSilently": [],
"vcs.changelist.edit": [],
"vcs.log.copyRevision": [],
"vcs.log.refresh": [],
"vcs.log.focusTextFilter": [],
"vcs.log.copyCommitSubject": [],
"vcs.log.goToRef": [],
"vcs.log.editMessage": [],