fix(sync): Handle redirected beads directories in gitCommitBeadsDir

When beads directory is redirected to a different repository (via bd-arjb),
gitCommitBeadsDir() was running git add from the current working directory's
repo root instead of the beads directory's repo root, causing exit status 128.

This fix adds the same redirect handling already present in gitHasBeadsChanges()
and gitHasUncommittedBeadsChanges() - checking GetRedirectInfo() and using
filepath.Dir(beadsDir) as the repo root when redirected.

Fixes: git add failed: exit status 128 errors during bd sync
This commit is contained in:
slit
2026-01-13 11:51:20 -08:00
committed by Spencer Tobin
parent cae793b843
commit f36c8f6556

View File

@@ -209,10 +209,21 @@ func gitCommitBeadsDir(ctx context.Context, message string) error {
return fmt.Errorf("no .beads directory found")
}
// Get the repository root (handles worktrees properly)
repoRoot := getRepoRootForWorktree(ctx)
if repoRoot == "" {
return fmt.Errorf("cannot determine repository root")
// Determine the repository root
// When beads directory is redirected (bd-arjb), we need to run git commands
// from the directory containing the actual .beads/, not the current working directory
var repoRoot string
redirectInfo := beads.GetRedirectInfo()
if redirectInfo.IsRedirected {
// beadsDir is the target (e.g., /path/to/mayor/rig/.beads)
// We need to run git from the parent of .beads (e.g., /path/to/mayor/rig)
repoRoot = filepath.Dir(beadsDir)
} else {
// Get the repository root (handles worktrees properly)
repoRoot = getRepoRootForWorktree(ctx)
if repoRoot == "" {
return fmt.Errorf("cannot determine repository root")
}
}
// Stage only the specific sync-related files