From 0fab45689fd4e7bcd8f5e145598b1d9700f2d517 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 18 Nov 2026 18:53:43 +0800 Subject: [PATCH] fix(vcs): expire the conflict notice once the merge or rebase is over (#4251) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "All conflicts resolved" kept its Commit… and Abort Merge actions after the merge was committed, and Abort Merge then reported no merge in progress. The conflict notices (key vcs.conflicts) now expire when the repository leaves the merge, rebase, cherry-pick, revert or am they refer to, however it ended. Fixes #4154 --- .../vcs/__tests__/operationNotices.test.ts | 32 +++++++++++++++++++ src/features/vcs/index.ts | 3 +- src/features/vcs/operations.tsx | 11 +++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/features/vcs/__tests__/operationNotices.test.ts diff --git a/src/features/vcs/__tests__/operationNotices.test.ts b/src/features/vcs/__tests__/operationNotices.test.ts new file mode 100644 index 000000000..fdc432cf3 --- /dev/null +++ b/src/features/vcs/__tests__/operationNotices.test.ts @@ -0,0 +1,32 @@ +import { afterEach, beforeEach, expect, it, vi } from "vitest"; +import type { BranchInfo } from "@/bindings"; +import { installOperationNoticeExpiry } from "../operations"; +import { useVcs } from "../store"; + +const { expire } = vi.hoisted(() => ({ expire: vi.fn() })); +vi.mock("@/workbench/contributions", async (original) => ({ + ...(await original()), + notifications: () => ({ notify: vi.fn(), expire }), +})); + +const branch = (operation: string | null) => ({ head: "main", operation }) as unknown as BranchInfo; +let dispose: () => void; + +beforeEach(() => { + expire.mockClear(); + useVcs.setState({ branch: branch("merge") }); + dispose = installOperationNoticeExpiry(); +}); +afterEach(() => dispose()); + +it("expires the conflict notice once the merge it offers to commit or abort is over", () => { + useVcs.setState({ branch: branch("merge") }); + expect(expire).not.toHaveBeenCalled(); + useVcs.setState({ branch: branch(null) }); + expect(expire).toHaveBeenCalledWith("vcs.conflicts"); +}); + +it("keeps it while an operation is still in progress", () => { + useVcs.setState({ branch: branch("rebase") }); + expect(expire).not.toHaveBeenCalled(); +}); diff --git a/src/features/vcs/index.ts b/src/features/vcs/index.ts index b3213e5d2..be23a90a8 100644 --- a/src/features/vcs/index.ts +++ b/src/features/vcs/index.ts @@ -20,7 +20,7 @@ import { registerVcsActions } from "./actions"; import { installChangelists } from "./changelists"; import { registerHistoryActions, trackOperationContext } from "./historyActions"; import { registerLogPaneActions } from "./logPaneActions"; -import { controlLabel, controlOperation, inProgress } from "./operations"; +import { controlLabel, controlOperation, inProgress, installOperationNoticeExpiry } from "./operations"; import { annotationsShown, blameSlot } from "./blame"; import { activateRevisionAnnotations } from "./annotateRevisionProvider"; import { inlineBlame } from "./inlineBlame"; @@ -195,6 +195,7 @@ export function activate(): () => void { useCommit.setState({ signOff: workflowSettings().vcs.git.signOff }); const disposers = [ installVcsStore(), + installOperationNoticeExpiry(), installRootSync(), installGitLog(), installDiagnosticsTracking(), diff --git a/src/features/vcs/operations.tsx b/src/features/vcs/operations.tsx index 2564fcf89..c51833306 100644 --- a/src/features/vcs/operations.tsx +++ b/src/features/vcs/operations.tsx @@ -56,6 +56,17 @@ export function inProgress(op: string | null | undefined = useVcs.getState().bra return op === "rebase" || op === "merge" || op === "cherry-pick" || op === "revert" || op === "am" ? op : null; } +/** + * Expires the conflict notices (key `vcs.conflicts`: Merge conflicts, All conflicts resolved) once + * the merge / rebase / cherry-pick they offer to continue or abort is over, however it ended. + */ +export function installOperationNoticeExpiry(): () => void { + return useVcs.subscribe((s, prev) => { + if (inProgress(prev.branch?.operation) && !inProgress(s.branch?.operation)) + notifications().expire?.("vcs.conflicts"); + }); +} + /** "Rebasing main", "Merging", "Cherry-picking"… for the branch widget and banner. */ export function operationTitle(op: InProgress, head: string | null): string { if (!head)