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,6 +1,7 @@
package main
import (
"context"
"encoding/json"
"fmt"
"os"
@@ -10,6 +11,7 @@ import (
"time"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/rpc"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/internal/ui"
@@ -248,8 +250,14 @@ func findPendingGates() ([]*types.Issue, error) {
}
// getGitBranchForGateDiscovery returns the current git branch name
// Uses CWD repo context since this is for user's project CI discovery
func getGitBranchForGateDiscovery() string {
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
rc, err := beads.GetRepoContext()
if err != nil {
return "main" // Default fallback
}
cmd := rc.GitCmdCWD(context.Background(), "rev-parse", "--abbrev-ref", "HEAD")
output, err := cmd.Output()
if err != nil {
return "main" // Default fallback
@@ -258,8 +266,14 @@ func getGitBranchForGateDiscovery() string {
}
// getGitCommitForGateDiscovery returns the current git commit SHA
// Uses CWD repo context since this is for user's project CI discovery
func getGitCommitForGateDiscovery() string {
cmd := exec.Command("git", "rev-parse", "HEAD")
rc, err := beads.GetRepoContext()
if err != nil {
return ""
}
cmd := rc.GitCmdCWD(context.Background(), "rev-parse", "HEAD")
output, err := cmd.Output()
if err != nil {
return ""