fix(worktree): prevent branch prefix conflicts#143
Open
FourWindff wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevents creating worktree branches whose prefix path conflicts with an existing local branch. For example, if branch
featurealready exists, the user can no longer createfeature/login/task-abc123.Changes
electron/ipc/git.ts): AddfindLocalBranchPrefixConflictwhich checks all prefix segments of the target branch name against existing local branches viagit rev-parsebefore runninggit worktree add -b.src/lib/branch-name.ts): AddfindBranchPrefixConflictto detect conflicts using the in-memory branch list, andbranchPrefixConflictErrorfor shared error message formatting.src/components/NewTaskDialog.tsx): Wrap conflict detection increateMemofor efficiency; disable submit button and show inline error when a conflict exists.src/components/BranchPrefixField.tsx): Accepterrorprop, render red border and error text.How it works
Git stores branches as ref files under
.git/refs/heads/. A branch namedfeaturecreates a file at that path, which blocks any branch whose name starts withfeature/(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
main) → submit disabled, error shownmain/task) → submit disabled, error shown🤖 Generated with Claude Code