Skip to content

fix: clean up empty parent directories after pruning worktrees#137

Merged
avihut merged 2 commits intomasterfrom
daft-135/top-level-prune
Feb 1, 2026
Merged

fix: clean up empty parent directories after pruning worktrees#137
avihut merged 2 commits intomasterfrom
daft-135/top-level-prune

Conversation

@avihut
Copy link
Owner

@avihut avihut commented Feb 1, 2026

Summary

  • After pruning a worktree for a branch with slashes (e.g., feature/my-branch), walk up the directory tree and remove any empty ancestor directories up to the project root
  • Replace the multi-remote-only cleanup_empty_remote_dir with a general cleanup_empty_parent_dirs that works unconditionally for all worktrees
  • Silence "Nothing to prune" output when no action is taken, following Git conventions

Test plan

  • Added test_prune_empty_parent_dir_cleanup integration test covering the exact scenario from the issue: two sibling branches under a shared prefix, pruning one keeps the parent, pruning both removes the parent
  • All 14 prune integration tests pass
  • All 140 unit tests pass
  • cargo clippy and cargo fmt clean

Fixes #135

🤖 Generated with Claude Code

avihut and others added 2 commits February 2, 2026 00:33
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 avihut self-assigned this Feb 1, 2026
@avihut avihut added bug Something isn't working fix Bug fix labels Feb 1, 2026
@avihut avihut added this to the v1.1.0 milestone Feb 1, 2026
@avihut avihut merged commit d32c9c8 into master Feb 1, 2026
5 checks passed
@avihut avihut deleted the daft-135/top-level-prune branch February 1, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gwtprune doesn't remove top level directory of work tree for branch with slash

1 participant