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)