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

@@ -82,6 +82,10 @@ var (
// Auto-flush manager (replaces timer-based approach to fix bd-52)
flushManager *FlushManager
// skipFinalFlush is set by sync command when sync.branch mode completes successfully.
// This prevents PersistentPostRun from re-exporting and dirtying the working directory.
skipFinalFlush = false
// Auto-import state
autoImportEnabled = true // Can be disabled with --no-auto-import
@@ -613,7 +617,8 @@ var rootCmd = &cobra.Command{
// Otherwise, handle direct mode cleanup
// Shutdown flush manager (performs final flush if needed)
if flushManager != nil {
// Skip if sync command already handled export and restore (sync.branch mode)
if flushManager != nil && !skipFinalFlush {
if err := flushManager.Shutdown(); err != nil {
fmt.Fprintf(os.Stderr, "Warning: flush manager shutdown error: %v\n", err)
}