diff --git a/cmd/bd/daemon_sync_branch.go b/cmd/bd/daemon_sync_branch.go index ac002689..f50b5873 100644 --- a/cmd/bd/daemon_sync_branch.go +++ b/cmd/bd/daemon_sync_branch.go @@ -161,7 +161,8 @@ func gitCommitInWorktree(ctx context.Context, worktreePath, filePath, message st } // Stage the file - addCmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "add", relPath) // #nosec G204 - worktreePath and relPath are derived from trusted git operations + // Use --sparse to work correctly with sparse-checkout enabled worktrees (fixes #1076) + addCmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "add", "--sparse", relPath) // #nosec G204 - worktreePath and relPath are derived from trusted git operations if err := addCmd.Run(); err != nil { return fmt.Errorf("git add failed in worktree: %w", err) } diff --git a/cmd/bd/migrate_sync.go b/cmd/bd/migrate_sync.go index 5b95f1a8..1546fc03 100644 --- a/cmd/bd/migrate_sync.go +++ b/cmd/bd/migrate_sync.go @@ -339,7 +339,8 @@ func commitInitialSyncState(ctx context.Context, worktreePath, jsonlRelPath stri beadsRelDir := filepath.Dir(jsonlRelPath) // Stage all beads files - addCmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "add", beadsRelDir) + // Use --sparse to work correctly with sparse-checkout enabled worktrees (fixes #1076) + addCmd := exec.CommandContext(ctx, "git", "-C", worktreePath, "add", "--sparse", beadsRelDir) if err := addCmd.Run(); err != nil { return fmt.Errorf("git add failed: %w", err) } diff --git a/cmd/bd/sync_branch.go b/cmd/bd/sync_branch.go index c109c5aa..a7f2a9ab 100644 --- a/cmd/bd/sync_branch.go +++ b/cmd/bd/sync_branch.go @@ -304,7 +304,8 @@ func commitToExternalBeadsRepo(ctx context.Context, beadsDir, message string, pu relBeadsDir = beadsDir // Fallback to absolute path } - addCmd := exec.CommandContext(ctx, "git", "-C", repoRoot, "add", relBeadsDir) //nolint:gosec // paths from trusted sources + // Use --sparse to work correctly with sparse-checkout enabled worktrees (fixes #1076) + addCmd := exec.CommandContext(ctx, "git", "-C", repoRoot, "add", "--sparse", relBeadsDir) //nolint:gosec // paths from trusted sources if output, err := addCmd.CombinedOutput(); err != nil { return false, fmt.Errorf("git add failed: %w\n%s", err, output) } diff --git a/internal/syncbranch/worktree.go b/internal/syncbranch/worktree.go index 485a486a..664d0a3f 100644 --- a/internal/syncbranch/worktree.go +++ b/internal/syncbranch/worktree.go @@ -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) }