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:
committed by
Steve Yegge
parent
31df1bb2c1
commit
eea4435269
@@ -205,10 +205,11 @@ func attachToTmuxSession(sessionID string) error {
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// ensureMainBranch checks if a git directory is on main branch.
|
||||
// ensureDefaultBranch checks if a git directory is on the default branch.
|
||||
// If not, warns the user and offers to switch.
|
||||
// Returns true if on main (or switched to main), false if user declined.
|
||||
func ensureMainBranch(dir, roleName string) bool { //nolint:unparam // bool return kept for future callers to check
|
||||
// Returns true if on default branch (or switched to it), false if user declined.
|
||||
// The rigPath parameter is used to look up the configured default branch.
|
||||
func ensureDefaultBranch(dir, roleName, rigPath string) bool { //nolint:unparam // bool return kept for future callers to check
|
||||
g := git.NewGit(dir)
|
||||
|
||||
branch, err := g.CurrentBranch()
|
||||
@@ -217,31 +218,38 @@ func ensureMainBranch(dir, roleName string) bool { //nolint:unparam // bool retu
|
||||
return true
|
||||
}
|
||||
|
||||
if branch == "main" || branch == "master" {
|
||||
// Get configured default branch for this rig
|
||||
defaultBranch := "main" // fallback
|
||||
if rigCfg, err := rig.LoadRigConfig(rigPath); err == nil && rigCfg.DefaultBranch != "" {
|
||||
defaultBranch = rigCfg.DefaultBranch
|
||||
}
|
||||
|
||||
if branch == defaultBranch || branch == "master" {
|
||||
return true
|
||||
}
|
||||
|
||||
// Warn about wrong branch
|
||||
fmt.Printf("\n%s %s is on branch '%s', not main\n",
|
||||
fmt.Printf("\n%s %s is on branch '%s', not %s\n",
|
||||
style.Warning.Render("⚠"),
|
||||
roleName,
|
||||
branch)
|
||||
fmt.Println(" Persistent roles should work on main to avoid orphaned work.")
|
||||
branch,
|
||||
defaultBranch)
|
||||
fmt.Printf(" Persistent roles should work on %s to avoid orphaned work.\n", defaultBranch)
|
||||
fmt.Println()
|
||||
|
||||
// Auto-switch to main
|
||||
fmt.Printf(" Switching to main...\n")
|
||||
if err := g.Checkout("main"); err != nil {
|
||||
fmt.Printf(" %s Could not switch to main: %v\n", style.Error.Render("✗"), err)
|
||||
fmt.Println(" Please manually run: git checkout main && git pull")
|
||||
// Auto-switch to default branch
|
||||
fmt.Printf(" Switching to %s...\n", defaultBranch)
|
||||
if err := g.Checkout(defaultBranch); err != nil {
|
||||
fmt.Printf(" %s Could not switch to %s: %v\n", style.Error.Render("✗"), defaultBranch, err)
|
||||
fmt.Printf(" Please manually run: git checkout %s && git pull\n", defaultBranch)
|
||||
return false
|
||||
}
|
||||
|
||||
// Pull latest
|
||||
if err := g.Pull("origin", "main"); err != nil {
|
||||
if err := g.Pull("origin", defaultBranch); err != nil {
|
||||
fmt.Printf(" %s Pull failed (continuing anyway): %v\n", style.Warning.Render("⚠"), err)
|
||||
} else {
|
||||
fmt.Printf(" %s Switched to main and pulled latest\n", style.Success.Render("✓"))
|
||||
fmt.Printf(" %s Switched to %s and pulled latest\n", style.Success.Render("✓"), defaultBranch)
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user