feat(context): centralize RepoContext API for git operations (#1102)

Centralizes repository context resolution via RepoContext API, fixing bugs where git commands run in the wrong repo when BEADS_DIR points elsewhere or in worktree scenarios.
This commit is contained in:
Peter Chanthamynavong
2026-01-15 07:55:08 -08:00
committed by GitHub
parent 159114563b
commit 0a48519561
33 changed files with 3211 additions and 327 deletions

View File

@@ -1,9 +1,9 @@
package main
import (
"context"
"fmt"
"os"
"os/exec"
"runtime/debug"
"strings"
@@ -152,11 +152,13 @@ func resolveBranch() string {
// Fallback: try to get branch from git at runtime
// Use symbolic-ref to work in fresh repos without commits
cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
cmd.Dir = "."
if output, err := cmd.Output(); err == nil {
if branch := strings.TrimSpace(string(output)); branch != "" && branch != "HEAD" {
return branch
// Uses CWD repo context since this shows user's current branch
if rc, err := beads.GetRepoContext(); err == nil {
cmd := rc.GitCmdCWD(context.Background(), "symbolic-ref", "--short", "HEAD")
if output, err := cmd.Output(); err == nil {
if branch := strings.TrimSpace(string(output)); branch != "" && branch != "HEAD" {
return branch
}
}
}