Skip to content

fix(worktree): prevent branch prefix conflicts#143

Open
FourWindff wants to merge 1 commit into
johannesjo:mainfrom
FourWindff:fix/branch-prefix-conflict-detection
Open

fix(worktree): prevent branch prefix conflicts#143
FourWindff wants to merge 1 commit into
johannesjo:mainfrom
FourWindff:fix/branch-prefix-conflict-detection

Conversation

@FourWindff
Copy link
Copy Markdown
Contributor

@FourWindff FourWindff commented May 25, 2026

Summary

Prevents creating worktree branches whose prefix path conflicts with an existing local branch. For example, if branch feature already exists, the user can no longer create feature/login/task-abc123.

Changes

  • Backend (electron/ipc/git.ts): Add findLocalBranchPrefixConflict which checks all prefix segments of the target branch name against existing local branches via git rev-parse before running git worktree add -b.
  • Frontend (src/lib/branch-name.ts): Add findBranchPrefixConflict to detect conflicts using the in-memory branch list, and branchPrefixConflictError for shared error message formatting.
  • UI (src/components/NewTaskDialog.tsx): Wrap conflict detection in createMemo for efficiency; disable submit button and show inline error when a conflict exists.
  • UI (src/components/BranchPrefixField.tsx): Accept error prop, render red border and error text.

How it works

Git stores branches as ref files under .git/refs/heads/. A branch named feature creates a file at that path, which blocks any branch whose name starts with feature/ (e.g. feature/login). This PR detects that condition both in the UI (early, with memoization) and at the backend (as a safety boundary).

Test plan

  • Open New Task dialog for a git project
  • Set branch prefix to an existing branch name (e.g. main) → submit disabled, error shown
  • Set branch prefix to a path starting with existing branch (e.g. main/task) → submit disabled, error shown
  • Set a non-conflicting prefix → submit enabled
  • Backend returns clear error message if frontend check is bypassed

🤖 Generated with Claude Code

Detect when a new worktree branch would conflict with an existing local
branch (e.g. creating "feature/login" when "feature" already exists).

- Backend: add findLocalBranchPrefixConflict in git.ts to check all
  prefix segments before git worktree add -b
- Frontend: add findBranchPrefixConflict in branch-name.ts with
  createMemo caching; disable submit and show inline error when
  prefix conflicts
- BranchPrefixField: accept error prop, show red border + error text

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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