feat(remove): instant worktree removal via move-then-delete#773
Open
feat(remove): instant worktree removal via move-then-delete#773
Conversation
Make background removal instant by renaming the worktree to a staging path before spawning the background process. This eliminates the 1-second sleep and makes the worktree path unavailable immediately. The new approach: 1. Rename worktree to staging path (instant, same filesystem) 2. Prune git metadata synchronously via `git worktree prune` 3. Background: `rm -rf` the staged directory + branch deletion Falls back to legacy `git worktree remove` if rename fails (cross- filesystem, permissions, Windows file locking). Also fixes: - Show hooks_run_at path when cwd becomes invalid after rename - Use `--` in rm/git commands to prevent option parsing for paths starting with `-` Co-Authored-By: Claude <noreply@anthropic.com>
- Update generate_removing_path() to use get_now() utility for deterministic timestamps in tests (respects WT_TEST_EPOCH) - Add test_remove_background_fallback_on_rename_failure test that exercises the fallback path when std::fs::rename() fails - The test blocks the rename by creating a file at the expected staged path, forcing fallback to legacy git worktree remove Co-Authored-By: Claude <noreply@anthropic.com>
# Conflicts: # src/output/handlers.rs
Resolved conflicts in: - src/commands/process.rs: Combined imports (FromStr, IntoEnumIterator, HookType) and merged both test sets (generate_removing_path, build_remove_command_staged from HEAD; hook_log tests from main) - src/output/handlers.rs: Combined imports (HookLog, InternalOp from main; build_remove_command_staged, generate_removing_path from HEAD) Co-Authored-By: Claude <noreply@anthropic.com>
Resolve conflict in src/output/handlers.rs: keep both the new instant removal functions (build_remove_command_staged, generate_removing_path) from remove-speed and the refactored hooks module imports from main. Co-Authored-By: Claude <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
wt removeinstant by renaming the worktree to a staging path before spawning the background processgit worktree removeif rename fails (cross-filesystem, permissions, Windows file locking)How it works
<path>.wt-removing-<timestamp>) — instant on same filesystemgit worktree prune— fast, no recursive file I/Orm -rfthe staged directory + branch deletionAdditional fixes
hooks_run_atpath when cwd becomes invalid after rename--inrm/gitcommands to prevent option parsing for paths starting with-Test plan
test_remove_background_path_gone_immediately— worktree path gone immediatelytest_remove_background_git_metadata_pruned— git metadata pruned immediatelytest_remove_background_deletes_merged_branch— branch deletion works with staged removaltest_remove_worktree_with_special_path_chars— paths with special chars handled correctly🤖 Generated with Claude Code