feat: allow pruning merged worktrees without --force#169
Merged
Conversation
Targeted prune (`wt prune <branch>`) now checks merge status before requiring --force. Branches merged locally or via PR can be pruned without -f; unmerged branches still require it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
raphi011
added a commit
that referenced
this pull request
Apr 5, 2026
Reverts the local branch ancestry check introduced in #169. Pruning without --force now requires forge-confirmed PR merge status only. Also adds open-PR protection for stale detection, and refactors cd/checkout interactive flows into helper functions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
raphi011
added a commit
that referenced
this pull request
Apr 5, 2026
…171) Reverts the local branch ancestry check introduced in #169. The locally-merged detection using `git branch --merged` had a fundamental limitation: it doesn't work for squash-merges (the dominant workflow on GitHub). This caused false negatives where squash-merged branches wouldn't be auto-prunable, and false positives where local merges for other reasons (e.g. testing) could trigger unwanted pruning. Pruning without `--force` now requires forge-confirmed PR merge status only. The `--refresh-pr` hint is surfaced in the error message. Additional changes: - Open-PR worktrees are now protected from stale detection (`isStaleWorktree` returns false when `PRState == open`) - Refactors `cd_cmd.go` interactive/recent/target paths into `runCdInteractive`, `runCdRecent`, `runCdTarget` helpers - Refactors `checkout_cmd.go` interactive block into `runCheckoutInteractive` helper ## Breaking Changes - None ## Test Coverage - Unit tests added: 5 (4 for `isStaleWorktree` with PR states, 1 `TestIsWorktreePrunable`) - Integration tests added: 0 --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Targeted prune (
wt prune <branch>) now checks merge status (locally merged or merged PR via cache) before requiring--force. Merged worktrees can be pruned without-f; unmerged ones still require it, with the error message listing only the unmerged branches.Breaking Changes
wt prune <branch>no longer unconditionally requires-f. Merged branches are pruned directly; only unmerged branches need--force.Test Coverage
TestPrune_MergedBranch_NoForceRequired,TestPrune_UnmergedBranch_RequiresForce,TestPrune_MixedTargets_RequiresForce)🤖 Generated with Claude Code