fix(sync): prevent final flush after sync.branch restore

When sync.branch is configured, the sync command:
1. Exports changes to JSONL
2. Commits to sync branch via worktree
3. Pulls from sync branch
4. Restores .beads/ from HEAD to keep working directory clean

But PersistentPostRun's flushManager.Shutdown() was re-exporting to JSONL,
undoing the restore and leaving modified files.

Fix: Set skipFinalFlush flag when sync.branch mode completes successfully.
This prevents the final export in PersistentPostRun.

Also: Skip push to main branch when sync.branch is configured - all
pushes should go through the sync branch worktree.
This commit is contained in:
Steve Yegge
2025-12-01 20:51:12 -08:00
parent 9483ab053e
commit 8ef3d81108
2 changed files with 13 additions and 3 deletions

View File

@@ -577,8 +577,10 @@ Use --merge to merge the sync branch back to main branch.`,
}
}
// Step 5: Push to remote (skip if already pushed via sync branch worktree)
if !noPush && hasChanges && !pushedViaSyncBranch {
// Step 5: Push to remote (skip if using sync branch - all pushes go via worktree)
// When sync.branch is configured, we don't push the main branch at all.
// The sync branch worktree handles all pushes.
if !noPush && hasChanges && !pushedViaSyncBranch && !useSyncBranch {
if dryRun {
fmt.Println("→ [DRY RUN] Would push to remote")
} else {
@@ -616,6 +618,9 @@ Use --merge to merge the sync branch back to main branch.`,
// Non-fatal - just means git status will show modified files
debug.Logf("sync: failed to restore .beads/ from branch: %v", err)
}
// Skip final flush in PersistentPostRun - we've already exported to sync branch
// and restored the working directory to match the current branch
skipFinalFlush = true
}
fmt.Println("\n✓ Sync complete")