fix: prevent prune from deleting worktrees with uncommitted changes#240
Merged
fix: prevent prune from deleting worktrees with uncommitted changes#240
Conversation
…r untracked files Previously, `git-worktree-prune` unconditionally passed `--force` to `git worktree remove`, silently deleting any uncommitted changes or untracked files in worktrees being pruned. This could cause data loss with no way to recover. Now prune checks each worktree for dirty state before removing it. If uncommitted changes or untracked files are detected, the worktree is skipped with a warning. A new `--force` / `-f` flag allows users to explicitly opt-in to removing dirty worktrees when intended. Co-Authored-By: Claude Opus 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.
Summary
git-worktree-prunenow checks each worktree for uncommitted changes or untracked files before removing it--force/-fflag to explicitly opt-in to removing dirty worktreesPreviously, prune unconditionally passed
--forcetogit worktree remove, which silently destroyed any uncommitted work or untracked files in worktrees being pruned. This caused data loss with no recovery path.Test plan
test_prune_skips_untracked_files— verifies untracked files are preserved without--forcetest_prune_skips_uncommitted_changes— verifies modified tracked files are preserved without--forcetest_prune_force_removes_dirty_worktree— verifies--forceremoves dirty worktreestest_prune_removes_clean_worktree— verifies clean worktrees still get removed normally🤖 Generated with Claude Code