From 659f52d6bd8e69b9f9e4b6939272146470757557 Mon Sep 17 00:00:00 2001 From: amber Date: Sun, 4 Jan 2026 16:21:20 -0800 Subject: [PATCH] fix(sync): avoid double export when uncommitted JSONL detected (bd-uuo9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add alreadyExported flag to skip redundant export. When gitHasUncommittedBeadsChanges() detects uncommitted changes, we export at line 175. The flag prevents the normal flow from exporting again at line 293. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- cmd/bd/sync.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/bd/sync.go b/cmd/bd/sync.go index bcbc8557..9f800b7d 100644 --- a/cmd/bd/sync.go +++ b/cmd/bd/sync.go @@ -166,6 +166,8 @@ Use --merge to merge the sync branch back to main branch.`, // 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. + // Track if we already exported during pre-flight to avoid redundant export later. + alreadyExported := false if hasUncommitted, err := gitHasUncommittedBeadsChanges(ctx); err != nil { fmt.Fprintf(os.Stderr, "Warning: failed to check for uncommitted changes: %v\n", err) } else if hasUncommitted { @@ -176,6 +178,7 @@ Use --merge to merge the sync branch back to main branch.`, FatalError("re-exporting to reconcile state: %v", err) } fmt.Println("✓ State reconciled") + alreadyExported = true } // GH#638: Check sync.branch BEFORE upstream check @@ -287,7 +290,7 @@ Use --merge to merge the sync branch back to main branch.`, } } - if !skipExport { + if !skipExport && !alreadyExported { // Pre-export integrity checks if err := ensureStoreActive(); err == nil && store != nil { if err := validatePreExport(ctx, store, jsonlPath); err != nil {