Fix: Use dynamic JSONL path in daemon sync branch operations (#361)

Fixes #359

The daemon's sync branch logic was hardcoding the JSONL path to .beads/beads.jsonl, ignoring the dynamic discovery logic used elsewhere. This caused sync failures in repositories where the JSONL file has a different name (e.g., beads.base.jsonl, issues.jsonl).

Changes:
- Updated cmd/bd/daemon_sync_branch.go to use findJSONLPath() instead of hardcoded path
- Implemented relative path calculation for correct worktree placement
- Applied fix to both push (sync to worktree) and pull (sync from worktree) operations

This works together with PR #360 to fix team/protected branch sync issues.

Co-authored-by: Charles P. Cross <cpdata@users.noreply.github.com>
This commit is contained in:
Charles P. Cross
2025-11-22 19:57:39 -05:00
committed by GitHub
parent 9a2345f706
commit ea7b39e40b

View File

@@ -64,14 +64,24 @@ func syncBranchCommitAndPush(ctx context.Context, store storage.Storage, autoPus
}
// Sync JSONL file to worktree
// Use hardcoded relative path since JSONL is always at .beads/beads.jsonl
jsonlRelPath := filepath.Join(".beads", "beads.jsonl")
// Get the actual JSONL path (could be issues.jsonl, beads.base.jsonl, etc.)
jsonlPath := findJSONLPath()
if jsonlPath == "" {
return false, fmt.Errorf("JSONL path not found")
}
// Convert absolute path to relative path from repo root
jsonlRelPath, err := filepath.Rel(repoRoot, jsonlPath)
if err != nil {
return false, fmt.Errorf("failed to get relative JSONL path: %w", err)
}
if err := wtMgr.SyncJSONLToWorktree(worktreePath, jsonlRelPath); err != nil {
return false, fmt.Errorf("failed to sync JSONL to worktree: %w", err)
}
// Check for changes in worktree
worktreeJSONLPath := filepath.Join(worktreePath, ".beads", "beads.jsonl")
worktreeJSONLPath := filepath.Join(worktreePath, jsonlRelPath)
hasChanges, err := gitHasChangesInWorktree(ctx, worktreePath, worktreeJSONLPath)
if err != nil {
return false, fmt.Errorf("failed to check for changes in worktree: %w", err)
@@ -225,9 +235,21 @@ func syncBranchPull(ctx context.Context, store storage.Storage, log daemonLogger
log.log("Pulled sync branch %s", syncBranch)
// Get the actual JSONL path
jsonlPath := findJSONLPath()
if jsonlPath == "" {
return false, fmt.Errorf("JSONL path not found")
}
// Convert to relative path
jsonlRelPath, err := filepath.Rel(repoRoot, jsonlPath)
if err != nil {
return false, fmt.Errorf("failed to get relative JSONL path: %w", err)
}
// Copy JSONL back to main repo
worktreeJSONLPath := filepath.Join(worktreePath, ".beads", "beads.jsonl")
mainJSONLPath := filepath.Join(repoRoot, ".beads", "beads.jsonl")
worktreeJSONLPath := filepath.Join(worktreePath, jsonlRelPath)
mainJSONLPath := jsonlPath
// Check if worktree JSONL exists
if _, err := os.Stat(worktreeJSONLPath); os.IsNotExist(err) {