fix: clean up empty parent directories after pruning worktrees#137
Merged
fix: clean up empty parent directories after pruning worktrees#137
Conversation
When pruning a worktree for a branch with slashes (e.g., feature/my-branch), only the leaf directory was removed, leaving empty parent directories behind. Now walks up the directory tree after removal, deleting each empty ancestor until reaching the project root or a non-empty directory. Replaces the multi-remote-only `cleanup_empty_remote_dir` with a general `cleanup_empty_parent_dirs` that works unconditionally for all worktrees. Fixes #135 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Follow Git convention of producing no output when no action is taken. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
avihut
added a commit
that referenced
this pull request
Feb 1, 2026
Merged
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
feature/my-branch), walk up the directory tree and remove any empty ancestor directories up to the project rootcleanup_empty_remote_dirwith a generalcleanup_empty_parent_dirsthat works unconditionally for all worktreesTest plan
test_prune_empty_parent_dir_cleanupintegration test covering the exact scenario from the issue: two sibling branches under a shared prefix, pruning one keeps the parent, pruning both removes the parentcargo clippyandcargo fmtcleanFixes #135
🤖 Generated with Claude Code