From f36c8f65563a4b105236813ab2aaedb48d644f79 Mon Sep 17 00:00:00 2001 From: slit Date: Tue, 13 Jan 2026 11:51:20 -0800 Subject: [PATCH] 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 --- cmd/bd/sync_git.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/bd/sync_git.go b/cmd/bd/sync_git.go index ee9e7f17..c4144da7 100644 --- a/cmd/bd/sync_git.go +++ b/cmd/bd/sync_git.go @@ -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