Skip to content

Refuse to remove a branch attached to more than one worktree - #23

Merged
masawada merged 2 commits into
mainfrom
refuse-duplicate-branch-worktrees
Sep 3, 2026
Merged

masawada merged 2 commits into
mainfrom
refuse-duplicate-branch-worktrees

Conversation

@masawada

@masawada masawada commented Sep 3, 2026 •

Copy link
Copy Markdown
Owner

Why

  • git worktree add --force can attach a branch that is already checked out to a second worktree. eda remove then deletes the first worktree it finds and fails on git branch -D, leaving a partial state.
  • The WorktreeRemove hook resolves only the branch name from worktree_path, so in that state it deletes a worktree other than the one it was given.

What

  • Collect every linked worktree attached to the branch and refuse, before inspecting or removing an individual worktree, when there is more than one. The refusal is a refusalError, so the hook reports the worktrees as kept.
  • Tests for the removal logic (duplicates inside and outside the worktree root) and the hook.

@masawada
masawada merged commit 932b490 into main Sep 3, 2026
3 checks passed
@masawada
masawada deleted the refuse-duplicate-branch-worktrees branch September 3, 2026 02:58
@github-actions github-actions Bot mentioned this pull request Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant