fix: Prevent bd sync from committing non-.beads files (bd-trgb)

gitCommit() was adding the JSONL file but then committing ALL staged
changes (no pathspec). If other files were staged (e.g., deletions from
git add -A), they would be swept into the bd sync commit.

Fixed by adding pathspec to both gitCommit() and commitToExternalBeadsRepo()
so they only commit what they explicitly staged.

This was the root cause of PR #722 files being deleted - they were staged
for deletion in the working tree and got committed by bd sync.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-25 12:05:23 -08:00
parent 2392496b0c
commit 2f9d423ac8
2 changed files with 6 additions and 2 deletions

View File

@@ -893,7 +893,9 @@ func gitCommit(ctx context.Context, filePath string, message string) error {
}
// Commit from repo root context with config-based author and signing options
commitArgs := buildGitCommitArgs(repoRoot, message)
// Use pathspec to commit ONLY this file (bd-trgb fix)
// This prevents accidentally committing other staged files
commitArgs := buildGitCommitArgs(repoRoot, message, "--", relPath)
commitCmd := exec.CommandContext(ctx, "git", commitArgs...)
output, err := commitCmd.CombinedOutput()
if err != nil {

View File

@@ -240,10 +240,12 @@ func commitToExternalBeadsRepo(ctx context.Context, beadsDir, message string, pu
}
// Commit with config-based author and signing options
// Use pathspec to commit ONLY beads files (bd-trgb fix)
// This prevents accidentally committing other staged files
if message == "" {
message = fmt.Sprintf("bd sync: %s", time.Now().Format("2006-01-02 15:04:05"))
}
commitArgs := buildGitCommitArgs(repoRoot, message)
commitArgs := buildGitCommitArgs(repoRoot, message, "--", relBeadsDir)
commitCmd := exec.CommandContext(ctx, "git", commitArgs...) //nolint:gosec // args from buildGitCommitArgs
if output, err := commitCmd.CombinedOutput(); err != nil {
return false, fmt.Errorf("git commit failed: %w\n%s", err, output)