fix(done): detect default branch instead of hardcoding 'main' (#42)

Adds RemoteDefaultBranch() to git.go that detects the repo's actual
default branch by checking origin/HEAD, then falling back to checking
for origin/master or origin/main.

Updates done.go to use this detection instead of hardcoded "main":
- Line 168: CommitsAhead now uses detected default branch
- Line 173: Error message uses detected branch name
- Line 187: Target branch defaults to detected branch

Fixes repos using 'master' as default branch (pre-2020 repos).

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

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Steve Yegge <steve.yegge@gmail.com>
This commit is contained in:
medley
2026-01-03 12:53:38 -07:00
committed by GitHub
parent cfd24b6831
commit eabb1c5aa6
2 changed files with 38 additions and 5 deletions

View File

@@ -255,6 +255,36 @@ func (g *Git) DefaultBranch() string {
return "main"
}
// RemoteDefaultBranch returns the default branch from the remote (origin).
// This is useful in worktrees where HEAD may not reflect the repo's actual default.
// Checks origin/HEAD first, then falls back to checking if master/main exists.
// Returns "main" as final fallback.
func (g *Git) RemoteDefaultBranch() string {
// Try to get from origin/HEAD symbolic ref
out, err := g.run("symbolic-ref", "refs/remotes/origin/HEAD")
if err == nil && out != "" {
// Returns refs/remotes/origin/main -> extract branch name
parts := strings.Split(out, "/")
if len(parts) > 0 {
return parts[len(parts)-1]
}
}
// Fallback: check if origin/master exists
_, err = g.run("rev-parse", "--verify", "origin/master")
if err == nil {
return "master"
}
// Fallback: check if origin/main exists
_, err = g.run("rev-parse", "--verify", "origin/main")
if err == nil {
return "main"
}
return "main" // final fallback
}
// HasUncommittedChanges returns true if there are uncommitted changes.
func (g *Git) HasUncommittedChanges() (bool, error) {
status, err := g.Status()