feat(rig): Add --branch flag for custom default branch

Add --branch flag to `gt rig add` to specify a custom default branch
instead of auto-detecting from remote. This supports repositories that
use non-standard default branches like `develop` or `release`.

Changes:
- Add --branch flag to `gt rig add` command
- Store default_branch in rig config.json
- Propagate default branch to refinery, witness, daemon, and all commands
- Rename ensureMainBranch to ensureDefaultBranch for clarity
- Add Rig.DefaultBranch() method for consistent access
- Update crew/manager.go and swarm/manager.go to use rig config

Based on PR #49 by @kustrun - rebased and extended with additional fixes.

Co-authored-by: kustrun <kustrun@users.noreply.github.com>

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/crew/jack
2026-01-04 14:00:48 -08:00
committed by Steve Yegge
parent 31df1bb2c1
commit eea4435269
14 changed files with 135 additions and 56 deletions

View File

@@ -156,10 +156,11 @@ func (m *Manager) loadRig(name string, entry config.RigEntry) (*Rig, error) {
// AddRigOptions configures rig creation.
type AddRigOptions struct {
Name string // Rig name (directory name)
GitURL string // Repository URL
BeadsPrefix string // Beads issue prefix (defaults to derived from name)
LocalRepo string // Optional local repo for reference clones
Name string // Rig name (directory name)
GitURL string // Repository URL
BeadsPrefix string // Beads issue prefix (defaults to derived from name)
LocalRepo string // Optional local repo for reference clones
DefaultBranch string // Default branch (defaults to auto-detected from remote)
}
func resolveLocalRepo(path, gitURL string) (string, string) {
@@ -285,8 +286,17 @@ func (m *Manager) AddRig(opts AddRigOptions) (*Rig, error) {
fmt.Printf(" ✓ Created shared bare repo\n")
bareGit := git.NewGitWithDir(bareRepoPath, "")
// Detect default branch (main, master, etc.)
defaultBranch := bareGit.DefaultBranch()
// Determine default branch: use provided value or auto-detect from remote
var defaultBranch string
if opts.DefaultBranch != "" {
defaultBranch = opts.DefaultBranch
} else {
// Try to get default branch from remote first, fall back to local detection
defaultBranch = bareGit.RemoteDefaultBranch()
if defaultBranch == "" {
defaultBranch = bareGit.DefaultBranch()
}
}
rigConfig.DefaultBranch = defaultBranch
// Re-save config with default branch
if err := m.saveRigConfig(rigPath, rigConfig); err != nil {
@@ -314,6 +324,12 @@ func (m *Manager) AddRig(opts AddRigOptions) (*Rig, error) {
return nil, fmt.Errorf("cloning for mayor: %w", err)
}
}
// Checkout the default branch for mayor (clone defaults to remote's HEAD, not our configured branch)
mayorGit := git.NewGitWithDir("", mayorRigPath)
if err := mayorGit.Checkout(defaultBranch); err != nil {
return nil, fmt.Errorf("checking out default branch for mayor: %w", err)
}
fmt.Printf(" ✓ Created mayor clone\n")
// Check if source repo has .beads/ with its own prefix - if so, use that prefix.