fix(sync): add --sparse flag to git add for worktree compatibility (#1143)

Fixes #1076.

When git worktrees have sparse-checkout enabled, git add operations can
fail with 'outside of sparse-checkout cone' errors. Adding the --sparse
flag allows git to stage files outside the sparse-checkout cone.

Changes:
- Add --sparse flag to git add in daemon_sync_branch.go (line 165)
- Add --sparse flag to git add in migrate_sync.go (line 343)
- Add --sparse flag to git add in sync_branch.go (line 308)
- Add --sparse flag to git add in worktree.go (line 732)

All changes include comments referencing #1076 for traceability.
This commit is contained in:
Bo
2026-01-19 13:21:12 -05:00
committed by GitHub
parent 82426423fe
commit 6a4a6170e7
4 changed files with 8 additions and 4 deletions

View File

@@ -728,7 +728,8 @@ func commitInWorktree(ctx context.Context, worktreePath, jsonlRelPath, message s
// Use -f (force) to add files even if they're gitignored
// In contributor mode, .beads/ is excluded in .git/info/exclude but needs to be tracked in sync branch
addCmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "add", "-f", beadsRelDir)
// Use --sparse to work correctly with sparse-checkout enabled worktrees (fixes #1076)
addCmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "add", "-f", "--sparse", beadsRelDir)
if err := addCmd.Run(); err != nil {
return fmt.Errorf("git add failed in worktree: %w", err)
}