Repository navigation
fix(merge): preserve the default branch's worktree instead of erroring after the merge - #4853
Merged
Merged
Conversation
…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.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 mainand exit 1. The error came fromcheck_not_default_branch(...)?infinish_after_merge, which returned before post-merge hooks were registered. Every other condition that keeps the worktree (primary worktree, locked, nested,--no-remove) printsWorktree preserved (...)and continues; this one now does the same with○ Worktree preserved (default branch).wt merge --helpstep 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), withmainin a linked worktree, and you runwt merge developfrom themainworktree. The newtest_merge_preserves_default_branch_worktreesets that up withrepo_with_alternate_primary. On main it producedsuccess: falsewith 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 --helpinstead.Local verification: the new test,
test_docs_are_in_sync, and the help snapshots pass. Of the 300mergeintegration tests, all pass excepttest_merge_no_ff_signs_merge_commit, which fails the same way on unmodified main in this sandbox (it needs SSH signing).