fix(worktree): use rig's configured default branch for polecat/dog worktrees (#325)

When a rig is added with --branch <non-default>, polecats and dogs now
correctly create worktrees from origin/<configured-branch> instead of
always using main/HEAD.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
tanevanwifferen
2026-01-11 01:29:54 +01:00
committed by GitHub
parent 84b6780a87
commit d13922523a
2 changed files with 23 additions and 6 deletions
+11 -3
View File
@@ -261,11 +261,19 @@ func (m *Manager) AddWithOptions(name string, opts AddOptions) (*Polecat, error)
return nil, fmt.Errorf("finding repo base: %w", err)
}
// Determine the start point for the new worktree
// Use origin/<default-branch> to ensure we start from the rig's configured branch
defaultBranch := "main"
if rigCfg, err := rig.LoadRigConfig(m.rig.Path); err == nil && rigCfg.DefaultBranch != "" {
defaultBranch = rigCfg.DefaultBranch
}
startPoint := fmt.Sprintf("origin/%s", defaultBranch)
// Always create fresh branch - unique name guarantees no collision
// git worktree add -b polecat/<name>-<timestamp> <path>
// git worktree add -b polecat/<name>-<timestamp> <path> <startpoint>
// Worktree goes in polecats/<name>/<rigname>/ for LLM ergonomics
if err := repoGit.WorktreeAdd(clonePath, branchName); err != nil {
return nil, fmt.Errorf("creating worktree: %w", err)
if err := repoGit.WorktreeAddFromRef(clonePath, branchName, startPoint); err != nil {
return nil, fmt.Errorf("creating worktree from %s: %w", startPoint, err)
}
// NOTE: We intentionally do NOT write to CLAUDE.md here.