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

View File

@@ -10,6 +10,7 @@ import (
"github.com/steveyegge/gastown/internal/config"
"github.com/steveyegge/gastown/internal/git"
"github.com/steveyegge/gastown/internal/rig"
)
// Common errors
@@ -134,12 +135,20 @@ func (m *Manager) createRigWorktree(dogPath, dogName, rigName string) (string, e
return "", fmt.Errorf("finding repo base for %s: %w", rigName, 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(rigPath); err == nil && rigCfg.DefaultBranch != "" {
defaultBranch = rigCfg.DefaultBranch
}
startPoint := fmt.Sprintf("origin/%s", defaultBranch)
// Unique branch per dog-rig combination
branchName := fmt.Sprintf("dog/%s-%s-%d", dogName, rigName, time.Now().UnixMilli())
// Create worktree with new branch
if err := repoGit.WorktreeAdd(worktreePath, branchName); err != nil {
return "", fmt.Errorf("creating worktree: %w", err)
// Create worktree with new branch from default branch
if err := repoGit.WorktreeAddFromRef(worktreePath, branchName, startPoint); err != nil {
return "", fmt.Errorf("creating worktree from %s: %w", startPoint, err)
}
return worktreePath, nil

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.