Skip to content

fix(merge): preserve the default branch's worktree instead of erroring after the merge - #4853

Merged
max-sixty merged 1 commit into
mainfrom
nightly/clean-44687751125-merge
Nov 21, 2026
Merged

max-sixty merged 1 commit into
mainfrom
nightly/clean-44687751125-merge

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

wt merge <target> run from a linked worktree that holds the default branch merged and pushed successfully, then failed the command with ✗ Cannot remove the default branch main and exit 1. The error came from check_not_default_branch(...)? in finish_after_merge, which returned before post-merge hooks were registered. Every other condition that keeps the worktree (primary worktree, locked, nested, --no-remove) prints Worktree preserved (...) and continues; this one now does the same with ○ Worktree preserved (default branch). wt merge --help step 7 lists the new condition, and the generated docs mirrors are refreshed.

To reach it, the primary worktree has to be on another branch (say develop), with main in a linked worktree, and you run wt merge develop from the main worktree. The new test_merge_preserves_default_branch_worktree sets that up with repo_with_alternate_primary. On main it produced success: false with the error above; with the fix it exits 0, its snapshot ends with the preserve line, and the worktree still exists afterwards.

I picked preserving over keeping the error because the merge has already landed when this check runs, so an error there reports the merge as failed when it actually succeeded. If the error is the intended behavior, the alternative is to keep it and document it in wt merge --help instead.

Local verification: the new test, test_docs_are_in_sync, and the help snapshots pass. Of the 300 merge integration tests, all pass except test_merge_no_ff_signs_merge_commit, which fails the same way on unmodified main in this sandbox (it needs SSH signing).

…g after the merge

Running `wt merge <target>` from a linked worktree that holds the default
branch merged successfully, then failed the command with "Cannot remove the
default branch main" (exit 1). Because the error returned early, post-merge
hooks were never registered either.

Treat the default branch like the other removal guards (primary worktree,
locked, nested): print "Worktree preserved (default branch)" and continue.
`wt merge --help` now lists the condition.
@worktrunk-bot worktrunk-bot added the nightly-cleanup Issues found by nightly code quality sweep label Nov 20, 2026
@max-sixty
max-sixty merged commit f1dee26 into main Nov 21, 2026
36 of 45 checks passed
@max-sixty
max-sixty deleted the nightly/clean-44687751125-merge branch November 21, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nightly-cleanup Issues found by nightly code quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants