Skip to content

Let wt prune remove dirty merged worktrees with --force - #51

Merged
bkildow merged 1 commit into
mainfrom
feat/prune-force-dirty
Sep 4, 2026
Merged

Let wt prune remove dirty merged worktrees with --force#51
bkildow merged 1 commit into
mainfrom
feat/prune-force-dirty

Conversation

@bkildow

@bkildow bkildow commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • wt prune now checks each merged candidate for uncommitted changes and shows a STATUS column (clean / dirty).
  • Dirty merged worktrees are kept unless --force is given, and are skipped before teardown hooks run. The confirmation prompt counts only what will actually be removed.
  • Behavior change: --force now means "remove merged worktrees even if they have uncommitted changes", matching wt remove --force. It is forwarded to git worktree remove so worktrees git considers unclean for other reasons (e.g. submodules) are removed too.
  • New --yes flag skips the confirmation prompt. Scripts using wt prune --force for non-interactive runs should switch to --yes.
  • --help, README, and the wt agents guide document the new flags.

Previously prune ran git worktree remove without --force, so a dirty merged worktree failed with a warning after confirmation and after teardown hooks had already run.

Test plan

  • make dev (gofumpt, golangci-lint, go test ./..., build) passes
  • New unit tests: TestPartitionPrunable, TestPrunableStatus
  • New e2e script e2e/testdata/prune.txtar: dirty merged worktree kept without --force, Nothing to prune on rerun, --dry-run --force leaves it, --force --yes removes it
  • Manual: wt prune in a project with a dirty merged worktree shows the table, the kept-count warning, and the prompt

https://claude.ai/code/session_01VrT5beDfJZ5EwsN3RDCCS3

Prune tried `git worktree remove` without --force on every merged candidate,
so a merged worktree with uncommitted changes failed with a warning after the
user had already confirmed and after teardown hooks had run.

Prune now checks each merged candidate for uncommitted changes up front and
shows a STATUS column (clean/dirty). Dirty worktrees are kept unless --force
is given, and are skipped before teardown hooks run. The confirmation count
only includes worktrees that will actually be removed.

--force changes meaning to match `wt remove --force`: it removes merged
worktrees even when they have uncommitted changes, and is forwarded to git
so worktrees git considers unclean for other reasons (submodules) are removed
too. A new --yes flag takes over skipping the confirmation prompt. Help text,
README, and the agents guide are updated accordingly.

Claude-Session: https://claude.ai/code/session_01VrT5beDfJZ5EwsN3RDCCS3
@bkildow
bkildow merged commit 337f61f into main Sep 4, 2026
5 checks passed
@bkildow
bkildow deleted the feat/prune-force-dirty branch September 4, 2026 19:48
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