Skip to content

feat: allow pruning merged worktrees without --force#169

Merged
raphi011 merged 1 commit into
mainfrom
force-rune
Apr 1, 2026
Merged

feat: allow pruning merged worktrees without --force#169
raphi011 merged 1 commit into
mainfrom
force-rune

Conversation

@raphi011

@raphi011 raphi011 commented Apr 1, 2026

Copy link
Copy Markdown
Owner

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

  • Unit tests added: 0
  • Integration tests added: 3 (TestPrune_MergedBranch_NoForceRequired, TestPrune_UnmergedBranch_RequiresForce, TestPrune_MixedTargets_RequiresForce)

🤖 Generated with Claude Code

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

codecov Bot commented Apr 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.29412% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/wt/prune_cmd.go 85.29% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@raphi011
raphi011 merged commit afad701 into main Apr 1, 2026
2 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant