fix(sync): write to worktree JSONL only when sync-branch configured (#1133)
Fixes #1103: bd sync --merge fails when sync-branch configured due to skip-worktree/daemon write conflict. Root cause: When sync-branch is configured, daemon/bd writes to main's .beads/issues.jsonl which has skip-worktree set. This hides changes from `git status` but `git merge` still detects them, causing merge failures. Solution: When sync-branch is configured, redirect all JSONL writes to the worktree's JSONL only. Main's JSONL is now read-only and only updated via merges from the sync branch. Changes: - autoflush.go: findJSONLPath() now returns worktree JSONL path when sync-branch configured, with safeguards for test isolation - sync_branch.go: Remove incomplete skip-worktree manipulation code that is no longer needed with this architectural fix Data flow with sync-branch: 1. bd create -> SQLite 2. bd sync --flush-only -> worktree/.beads/issues.jsonl 3. bd sync --merge -> clean merge (main's JSONL unchanged) 4. auto-import -> SQLite updated from merged JSONL
This commit is contained in:
@@ -175,6 +175,11 @@ func mergeSyncBranch(ctx context.Context, dryRun bool) error {
|
||||
return fmt.Errorf("uncommitted changes detected - commit or stash them first")
|
||||
}
|
||||
|
||||
// GH#1103: Skip-worktree conflict handling removed.
|
||||
// The architectural fix ensures daemon/bd writes ONLY to the worktree JSONL
|
||||
// when sync-branch is configured, so main's JSONL never has uncommitted changes
|
||||
// that would conflict with merge. See autoflush.go:findJSONLPath()
|
||||
|
||||
fmt.Printf("Merging sync branch '%s' into '%s'...\n", syncBranch, currentBranch)
|
||||
|
||||
if dryRun {
|
||||
@@ -278,6 +283,11 @@ func getRepoRootFromPath(ctx context.Context, path string) (string, error) {
|
||||
return strings.TrimSpace(string(output)), nil
|
||||
}
|
||||
|
||||
// detectAndClearSkipWorktree and restoreSkipWorktree were removed in GH#1103.
|
||||
// The architectural fix ensures daemon/bd writes ONLY to the worktree JSONL
|
||||
// when sync-branch is configured, eliminating the need for skip-worktree manipulation.
|
||||
// See autoflush.go:findJSONLPath() for the implementation.
|
||||
|
||||
// commitToExternalBeadsRepo commits changes directly to an external beads repo.
|
||||
// Used when BEADS_DIR points to a different git repository than cwd.
|
||||
// This bypasses the worktree-based sync which fails when beads dir is external.
|
||||
|
||||
Reference in New Issue
Block a user