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:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user