Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

fix: clean up empty parent directories after worktree removal#41

Merged
davidpoblador merged 1 commit intomainfrom
fix/cleanup-empty-parent-dirs
Feb 9, 2026
Merged

fix: clean up empty parent directories after worktree removal#41
davidpoblador merged 1 commit intomainfrom
fix/cleanup-empty-parent-dirs

Conversation

@davidpoblador
Copy link
Member

Summary

  • After wt-rm or wt-destroy removes a worktree with a nested branch name (e.g., fix/issue-x), empty parent directories like fix/ were left behind
  • Added a loop to both recipes that walks up from the removed worktree's parent, removing empty directories until it hits the project root or a non-empty directory
  • Handles arbitrarily deep nesting (e.g., type/scope/name) and is safe when sibling worktrees share a prefix

Test plan

  • wt-add fix/test-1 then wt-rm fix/test-1fix/ directory is removed
  • wt-add fix/a and wt-add fix/b, then wt-rm fix/afix/ still exists (has fix/b)
  • wt-rm fix/bfix/ is now removed
  • wt-add deep/nested/branch, then wt-destroy deep/nested/branch — both deep/nested/ and deep/ are removed
  • wt-add flat-branch, then wt-rm flat-branch — no parent cleanup needed, works as before

🤖 Generated with Claude Code

When using nested branch names like `fix/issue-x`, removing the worktree
leaves empty parent directories behind. Add a loop to both wt-rm and
wt-destroy that walks up from the target's parent, removing empty
directories until it hits the project root or a non-empty directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@davidpoblador davidpoblador merged commit aba7142 into main Feb 9, 2026
1 check passed
@davidpoblador davidpoblador deleted the fix/cleanup-empty-parent-dirs branch February 9, 2026 18:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant