feat: detect uncommitted JSONL changes before sync (GH#885, bd-vd8e)
Add pre-flight safety check to detect when a previous sync exported but failed before commit, leaving JSONL in an inconsistent state. - Add gitHasUncommittedBeadsChanges() helper in sync_git.go - Call in sync pre-flight checks after merge/rebase check - If uncommitted changes detected, force re-export to reconcile state This catches the failure mode early before it compounds across worktrees. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
7b90678afe
commit
44a5c3a0ec
@@ -163,6 +163,21 @@ Use --merge to merge the sync branch back to main branch.`,
|
||||
FatalErrorWithHint("unmerged paths or merge in progress", "resolve conflicts, run 'bd import' if needed, then 'bd sync' again")
|
||||
}
|
||||
|
||||
// GH#885: Preflight check for uncommitted JSONL changes
|
||||
// This detects when a previous sync exported but failed before commit,
|
||||
// leaving the JSONL in an inconsistent state across worktrees.
|
||||
if hasUncommitted, err := gitHasUncommittedBeadsChanges(ctx); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Warning: failed to check for uncommitted changes: %v\n", err)
|
||||
} else if hasUncommitted {
|
||||
fmt.Println("→ Detected uncommitted JSONL changes (possible incomplete sync)")
|
||||
fmt.Println("→ Re-exporting from database to reconcile state...")
|
||||
// Force a fresh export to ensure JSONL matches current DB state
|
||||
if err := exportToJSONL(ctx, jsonlPath); err != nil {
|
||||
FatalError("re-exporting to reconcile state: %v", err)
|
||||
}
|
||||
fmt.Println("✓ State reconciled")
|
||||
}
|
||||
|
||||
// GH#638: Check sync.branch BEFORE upstream check
|
||||
// When sync.branch is configured, we should use worktree-based sync even if
|
||||
// the current branch has no upstream (e.g., detached HEAD in jj, git worktrees)
|
||||
|
||||
Reference in New Issue
Block a user