fix(polecat): handle existing branch gracefully in polecat add
When adding a polecat, check if the branch already exists (e.g., from a previous polecat that was removed but whose branch wasn't cleaned up). If so, reuse the existing branch with WorktreeAddExisting instead of failing with 'a branch named polecat/X already exists'. Fixes: gt-bmjw 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -74,10 +74,24 @@ func (m *Manager) Add(name string) (*Polecat, error) {
|
|||||||
return nil, fmt.Errorf("mayor clone not found at %s (run 'gt rig add' to set up rig structure)", mayorPath)
|
return nil, fmt.Errorf("mayor clone not found at %s (run 'gt rig add' to set up rig structure)", mayorPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create worktree with new branch
|
// Check if branch already exists (e.g., from previous polecat that wasn't cleaned up)
|
||||||
// git worktree add -b polecat/<name> <path>
|
branchExists, err := mayorGit.BranchExists(branchName)
|
||||||
if err := mayorGit.WorktreeAdd(polecatPath, branchName); err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("creating worktree: %w", err)
|
return nil, fmt.Errorf("checking branch existence: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create worktree - reuse existing branch if it exists
|
||||||
|
if branchExists {
|
||||||
|
// Branch exists, create worktree using existing branch
|
||||||
|
if err := mayorGit.WorktreeAddExisting(polecatPath, branchName); err != nil {
|
||||||
|
return nil, fmt.Errorf("creating worktree with existing branch: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Create new branch with worktree
|
||||||
|
// git worktree add -b polecat/<name> <path>
|
||||||
|
if err := mayorGit.WorktreeAdd(polecatPath, branchName); err != nil {
|
||||||
|
return nil, fmt.Errorf("creating worktree: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create polecat state - ephemeral polecats start in working state
|
// Create polecat state - ephemeral polecats start in working state
|
||||||
|
|||||||
Reference in New Issue
Block a user