-
-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
Description
Summary
Add worktree support to gh-poi: when a branch is identified as deletable, automatically remove any associated worktree before deleting the branch.
Motivation
Git worktrees allow developers to have multiple working directories from a single repository. A common workflow is:
git worktree add ../feature-123 feature-123
# work on feature, create PR, merge
gh poi # currently fails or leaves orphaned worktreeCurrently, gh poi cannot delete branches that have associated worktrees because:
- Git refuses to delete a branch checked out in any worktree
- After manual branch deletion, orphaned worktrees remain on disk
This forces users to manually manage worktrees, defeating the purpose of automated cleanup.
Proposed Solution
Behavior
- Detection: Before attempting branch deletion, check if the branch has an associated worktree using
git worktree list - Removal: For deletable branches with worktrees, run
git worktree remove <path>beforegit branch -D - Display: Show worktree paths in the output when they will be removed
New Flag
| Flag | Description |
|---|---|
--worktree |
Also remove worktrees associated with deletable branches |
Output Example
$ gh poi --worktree
Deleting branches...
✓ feature-123 (worktree: /home/user/projects/feature-123)
✓ bugfix-456 (worktree: /home/user/projects/bugfix-456)
✓ hotfix-789
3 branches deleted (2 worktrees removed)
Dry-run Support
$ gh poi --dry-run --worktree
Branches to delete:
- feature-123 (worktree: /home/user/projects/feature-123)
- bugfix-456 (worktree: /home/user/projects/bugfix-456)
- hotfix-789
Additional context
Edge Cases
| Case | Handling |
|---|---|
| Locked worktree | Skip with warning (user must run git worktree unlock manually) |
| Worktree has uncommitted changes | Skip with warning (user must handle manually) |
| Main worktree (repo root) | Never remove (implicit protection) |
| Worktree path no longer exists | Run git worktree prune first |
Metadata
Metadata
Assignees
Labels
No labels