diff --git a/src/components/FinishDialog.client.test.tsx b/src/components/FinishDialog.client.test.tsx index 7f1a9ee6f..a834ce660 100644 --- a/src/components/FinishDialog.client.test.tsx +++ b/src/components/FinishDialog.client.test.tsx @@ -681,20 +681,6 @@ describe('FinishDialog merge blocker', () => { ); }); - it('says next to the disabled merge button why it is disabled', async () => { - mockInvoke((channel) => { - if (channel === IPC.GetBranchLog) return ''; - if (channel === IPC.CheckMergeStatus) return { conflicting_files: [], main_ahead_count: 0 }; - return { current_branch: 'task/parent', has_committed_changes: false }; - }); - mount(); - await flush(); - expect(confirmButton()?.disabled).toBe(true); - expect(document.querySelector('[data-testid="footer-note"]')?.textContent).toBe( - 'No commits on this branch yet.', - ); - }); - it('asks for a commit when the changes are not committed yet', async () => { mockInvoke((channel) => { if (channel === IPC.GetBranchLog) return ''; @@ -750,6 +736,59 @@ describe('FinishDialog with the branch already on the base', () => { }); }); +describe('FinishDialog with no work on the branch', () => { + it('says nothing is left to merge and offers to close the task', async () => { + mockInvoke((channel) => { + if (channel === IPC.GetBranchLog) return ''; + if (channel === IPC.CheckMergeStatus) + return { + conflicting_files: [], + main_ahead_count: 3, + remote: 'unpushed', + target_uncommitted: { path: '/repo', files: ['a.ts'], overlap: ['a.ts'] }, + }; + return { + current_branch: 'task/parent', + has_committed_changes: false, + has_uncommitted_changes: false, + }; + }); + const handlers = mount(); + await flush(); + expect(document.body.textContent).toContain( + 'Nothing on this branch: it has no commits and no uncommitted changes, so nothing is left to merge.', + ); + expect(document.querySelector('[data-testid="target-uncommitted"]')).toBeNull(); + // The quiet notice says it all; no warning that the merge has nothing to bring in. + expect(document.body.textContent).not.toContain('Nothing to merge:'); + // An empty branch has nothing to push or to open a PR with. + expect(document.querySelector('section[aria-label="Pull request"]')).toBeNull(); + expect( + [...document.querySelectorAll('button')].some((b) => b.textContent?.trim() === 'Push'), + ).toBe(false); + expect(document.querySelector('[data-testid="footer-note"]')?.textContent).toBe(''); + expect(confirmButton()?.textContent).toBe('Close task'); + expect(confirmButton()?.disabled).toBe(false); + confirmButton()?.click(); + expect(mergeTask).not.toHaveBeenCalled(); + expect(handlers.onCloseTask).toHaveBeenCalled(); + }); + + it("does not offer to close while the worktree is off the task's branch", async () => { + mockInvoke((channel) => { + if (channel === IPC.GetBranchLog) return ''; + if (channel === IPC.CheckMergeStatus) return { conflicting_files: [], main_ahead_count: 0 }; + // The other branch may hold the task's work. + return { current_branch: 'task/other', has_committed_changes: false }; + }); + mount(); + await flush(); + expect(document.body.textContent).not.toContain('nothing is left to merge'); + expect(confirmButton()?.textContent).not.toBe('Close task'); + expect(confirmButton()?.disabled).toBe(true); + }); +}); + describe('FinishDialog with landed commits on another branch', () => { it("does not call the task landed while the worktree is off the task's branch", async () => { mockInvoke((channel) => { diff --git a/src/components/FinishDialog.tsx b/src/components/FinishDialog.tsx index eac2330cf..defe5698c 100644 --- a/src/components/FinishDialog.tsx +++ b/src/components/FinishDialog.tsx @@ -129,9 +129,12 @@ export function FinishDialog(props: FinishDialogProps) { headSha: () => (merge.worktreeStatus.error ? null : merge.worktreeStatus()?.head_sha), }); const prMerging = () => pr.busy() === 'merge'; - // Merged on GitHub, or the commits reached the base another way, such as a - // cherry-pick: either way closing the task is all that is left. - const landed = () => pr.mode() === 'merged' || (pr.mode() === 'local' && merge.alreadyLanded()); + // The commits reached the base another way, such as a cherry-pick, or the + // branch holds no work, such as when it went out on another branch. + const nothingLeft = () => merge.alreadyLanded() || merge.nothingToMerge(); + // Merged on GitHub, or nothing left to merge locally: either way closing the + // task is all that is left. + const landed = () => pr.mode() === 'merged' || (pr.mode() === 'local' && nothingLeft()); // A PR merges on GitHub, so a base that moved on locally matters only where // it conflicts or GitHub asks for the branch to be updated. const showBaseSync = () => { @@ -174,9 +177,7 @@ export function FinishDialog(props: FinishDialogProps) { const pushFirst = () => pr.mode() === 'pr' && pr.headDiffers(); // A local merge uses local commits, so pushing is only on offer, never required. const offerPush = () => - pr.mode() === 'local' && - !merge.alreadyLanded() && - (remote() === 'unpushed' || remote() === 'differs'); + pr.mode() === 'local' && !nothingLeft() && (remote() === 'unpushed' || remote() === 'differs'); // Undefined while loading; a loaded status without a remote means there is no origin. const createPrRemote = () => merge.mergeStatus.loading || merge.mergeStatus.error || !merge.mergeStatus() @@ -441,11 +442,11 @@ export function FinishDialog(props: FinishDialogProps) { {retroBox()} {/* Without a PR the section only offers one, where the PR shows once it exists; - without an origin, or with the work on the base already, it needs no word on PRs. */} + without an origin, or with nothing left to merge, it needs no word on PRs. */} + setCreatePrOpen(true)} @@ -470,7 +471,7 @@ export function FinishDialog(props: FinishDialogProps) { diff --git a/src/components/MergeSection.tsx b/src/components/MergeSection.tsx index d293217c8..86a8ea881 100644 --- a/src/components/MergeSection.tsx +++ b/src/components/MergeSection.tsx @@ -118,6 +118,22 @@ export function MergeBlockers(props: MergeSectionProps & { showBaseSync: boolean nothing is left to merge. + +
+ Nothing on this branch: it has no commits and no uncommitted changes, so nothing is left + to merge. +
+
- {/* No merge runs once the branch has landed, so the base checkout's changes do not matter. */} - + {/* No merge runs once the branch has landed or holds nothing, so the base checkout's changes do not matter. */} + {(target) => (
)} - + {/* A branch with no work at all has the quiet notice above: closing is the way out, nothing needs attention. */} +
mergeStatus()?.already_landed === true && !hasBranchMismatch(); + /** The task's branch holds no work at all, committed or not, such as when + * that work went out on another branch. A merge commit counts as work: it + * can carry changes of its own. */ + const nothingToMerge = () => { + const status = worktreeStatus(); + return ( + !!status && + !status.has_committed_changes && + !status.has_uncommitted_changes && + !hasBranchMismatch() + ); + }; /** Uncommitted changes in the base checkout; the merge sets them aside. */ const targetUncommitted = () => mergeStatus()?.target_uncommitted; /** The task's uncommitted files the base changed too: they block bringing it in. */ @@ -151,10 +163,8 @@ export function createMergeState(props: MergeStateProps) { const mergeBlocker = (): string | undefined => { if (!worktreeStatus()) return 'Checking the branch…'; if (hasBranchMismatch()) return "The worktree is not on this task's branch."; - if (!hasCommittedChangesToMerge()) - return worktreeStatus()?.has_uncommitted_changes - ? 'Commit the changes to merge them.' - : 'No commits on this branch yet.'; + // A branch with no work at all is nothingToMerge, which offers Close task instead. + if (!hasCommittedChangesToMerge()) return 'Commit the changes to merge them.'; if (hasConflicts()) return `Resolve the conflicts with ${baseBranchName()} first.`; if (targetUncommitted()?.overlap.length) return `Commit or stash the changes in ${baseBranchName()} that this merge touches.`; @@ -271,6 +281,7 @@ export function createMergeState(props: MergeStateProps) { commitCount, hasConflicts, alreadyLanded, + nothingToMerge, targetUncommitted, uncommittedOverlap, hasCommittedChangesToMerge,