Repository navigation
fix(remove): plan no branch deletion for an orphan worktree's unborn branch - #4233
Merged
Merged
Conversation
…branch An orphan worktree's branch has no ref until its first commit, so `wt remove` hinted at a `wt remove -D` that then fails, or (with --foreground) removed the worktree and exited 1 with git's "Needed a single revision". The planner now reads the unborn state from its ref snapshot and plans `Keep`, as it does for a branch a sibling checkout still uses, for both a live and a stale worktree. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
worktrunk-bot
approved these changes
Sep 22, 2026
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
BranchFate::NotAttempted in src/commands/worktree/types.rs enumerates the reasons a plan retains the branch — "deletion_mode Keep — shared checkout, or --no-delete-branch" — and that list was exhaustive before this change. Unborn is now a third reason, and it is the one a reader is most likely to be chasing: wt remove <orphan> --format json emits "branch_outcome": "not_attempted" and the docstring is where they'd look to interpret it. Worth adding to the parenthetical.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
An orphan worktree (
git worktree add --orphan) has an unborn branch until its first commit:HEADnamesrefs/heads/<branch>, but no such ref exists.wt removeplanned a branch deletion for it anyway, so it misreported the branch or failed:wt remove freshprinted↳ Branch unmerged; to delete, run wt remove -D fresh, a command that then fails withNo branch named fresh. With--foregroundit removed the worktree and then exited 1 with git'sfatal: Needed a single revision..gitgone):wt remove freshprinted✓ Pruned stale worktree for freshfollowed by○ Branch fresh retained; has unmerged changesand the samewt remove -Dhint.Now the removal planner treats an unborn branch as having nothing to delete and plans
Keepfor it, the way it already handles a branch that a sibling checkout still uses. The output is just✓ Removed fresh worktree(or◎ Removing fresh worktree in background) or✓ Pruned stale worktree for fresh. The planner reads this from the ref snapshot it already holds, so it adds no git call. The picker's removal goes through the same planner.test_remove_orphan_worktreeremoves a live and a stale orphan worktree, each with a remote-tracking branch of the same name. The remote branch catches a check that counts remote branches, which would take the branch for existing.🤖 Generated with Claude Code