fix: bd sync fails to copy local changes TO beads-sync worktree (#810)
The bug: In a bare repo + worktrees setup, jsonlRelPath was calculated relative to the project root (containing all worktrees), resulting in paths like "main/.beads/issues.jsonl". But the sync branch worktree uses sparse checkout for .beads/*, so files are at ".beads/issues.jsonl". This caused SyncJSONLToWorktreeWithOptions to write to the wrong location (e.g., worktree/main/.beads/ instead of worktree/.beads/), so changes made locally never reached the sync branch worktree. #785 fixed the reverse direction (worktree → local) by adding normalizeBeadsRelPath(), but the local → worktree direction was missed. Fix: - Export NormalizeBeadsRelPath() (uppercase) for cross-package use - Apply normalization in SyncJSONLToWorktreeWithOptions for dstPath - Apply normalization in daemon_sync_branch.go for worktreeJSONLPath in both commit and pull paths - Add unit tests for the normalization function 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -185,10 +185,10 @@ func (wm *WorktreeManager) SyncJSONLToWorktreeWithOptions(worktreePath, jsonlRel
|
||||
srcPath := filepath.Join(wm.repoPath, jsonlRelPath)
|
||||
|
||||
// Destination: worktree JSONL
|
||||
// GH#785: Handle bare repo worktrees where jsonlRelPath might include the
|
||||
// GH#785, GH#810: Handle bare repo worktrees where jsonlRelPath might include the
|
||||
// worktree name (e.g., "main/.beads/issues.jsonl"). The sync branch uses
|
||||
// sparse checkout for .beads/* so we normalize to strip leading components.
|
||||
normalizedRelPath := normalizeBeadsRelPath(jsonlRelPath)
|
||||
normalizedRelPath := NormalizeBeadsRelPath(jsonlRelPath)
|
||||
dstPath := filepath.Join(worktreePath, normalizedRelPath)
|
||||
|
||||
// Ensure destination directory exists
|
||||
@@ -320,22 +320,6 @@ func (wm *WorktreeManager) mergeJSONLFiles(srcData, dstData []byte) ([]byte, err
|
||||
return mergedData, nil
|
||||
}
|
||||
|
||||
|
||||
// normalizeBeadsRelPath strips any leading path components before .beads/.
|
||||
// This handles bare repo worktrees where the relative path includes the worktree
|
||||
// name (e.g., "main/.beads/issues.jsonl" -> ".beads/issues.jsonl").
|
||||
// GH#785: Fix for sync failing across worktrees in bare repo setup.
|
||||
func normalizeBeadsRelPath(relPath string) string {
|
||||
// Use filepath.ToSlash for consistent handling across platforms
|
||||
normalized := filepath.ToSlash(relPath)
|
||||
// Look for ".beads/" to ensure we match the directory, not a prefix like ".beads-backup"
|
||||
if idx := strings.Index(normalized, ".beads/"); idx > 0 {
|
||||
// Strip leading path components before .beads
|
||||
return filepath.FromSlash(normalized[idx:])
|
||||
}
|
||||
return relPath
|
||||
}
|
||||
|
||||
// isValidWorktree checks if the path is a valid git worktree
|
||||
func (wm *WorktreeManager) isValidWorktree(worktreePath string) (bool, error) {
|
||||
cmd := exec.Command("git", "worktree", "list", "--porcelain")
|
||||
@@ -437,6 +421,21 @@ func (wm *WorktreeManager) configureSparseCheckout(worktreePath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// NormalizeBeadsRelPath strips any leading path components before .beads/.
|
||||
// This handles bare repo worktrees where the relative path includes the worktree
|
||||
// name (e.g., "main/.beads/issues.jsonl" -> ".beads/issues.jsonl").
|
||||
// GH#785, GH#810: Fix for sync failing across worktrees in bare repo setup.
|
||||
func NormalizeBeadsRelPath(relPath string) string {
|
||||
// Use filepath.ToSlash for consistent handling across platforms
|
||||
normalized := filepath.ToSlash(relPath)
|
||||
// Look for ".beads/" to ensure we match the directory, not a prefix like ".beads-backup"
|
||||
if idx := strings.Index(normalized, ".beads/"); idx > 0 {
|
||||
// Strip leading path components before .beads
|
||||
return filepath.FromSlash(normalized[idx:])
|
||||
}
|
||||
return relPath
|
||||
}
|
||||
|
||||
// verifySparseCheckout checks if sparse checkout is configured correctly
|
||||
func (wm *WorktreeManager) verifySparseCheckout(worktreePath string) error {
|
||||
// Check if sparse-checkout file exists and contains .beads
|
||||
|
||||
Reference in New Issue
Block a user