fix(spawn): resolve variable shadowing and branch deletion edge case

- Move router and polecatAddress definitions before if block to avoid
  shadowing (defining same vars inside and after the block)
- Handle branch deletion failure in Recreate() by checking if branch
  still exists and using WorktreeAddExisting like Add() does

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-21 10:29:32 -08:00
parent e07eb96144
commit ae6f4c8185
2 changed files with 26 additions and 10 deletions

View File

@@ -281,11 +281,27 @@ func (m *Manager) Recreate(name string, force bool) (*Polecat, error) {
_ = mayorGit.WorktreePrune()
// Delete the old branch so worktree starts fresh from current HEAD
_ = mayorGit.DeleteBranch(branchName, true) // force delete
// Ignore error - branch may not exist (first recreate) or may fail to delete
_ = mayorGit.DeleteBranch(branchName, true)
// Create fresh worktree with new branch from current HEAD
if err := mayorGit.WorktreeAdd(polecatPath, branchName); err != nil {
return nil, fmt.Errorf("creating fresh worktree: %w", err)
// Check if branch still exists (deletion may have failed or branch was protected)
branchExists, err := mayorGit.BranchExists(branchName)
if err != nil {
return nil, fmt.Errorf("checking branch existence: %w", err)
}
// Create worktree - handle both cases like Add() does
if branchExists {
// Branch still exists, create worktree using existing branch
// This happens if delete failed (e.g., protected branch)
if err := mayorGit.WorktreeAddExisting(polecatPath, branchName); err != nil {
return nil, fmt.Errorf("creating worktree with existing branch: %w", err)
}
} else {
// Branch was deleted, create fresh worktree with new branch from HEAD
if err := mayorGit.WorktreeAdd(polecatPath, branchName); err != nil {
return nil, fmt.Errorf("creating fresh worktree: %w", err)
}
}
// Set up shared beads