fix(sync): initialize store after daemon disconnect (GH#984)

The sync command was closing the daemon connection without initializing
the direct store, leaving store=nil. This caused errors in post-checkout
hook when running bd sync --import-only.

Fixed by using fallbackToDirectMode() which properly closes daemon and
initializes the store.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
grip
2026-01-09 22:53:36 -08:00
committed by Steve Yegge
parent f03c754df1
commit 351f4c1dd7
7 changed files with 110 additions and 414 deletions

View File

@@ -65,10 +65,16 @@ Use --merge to merge the sync branch back to main branch.`,
// (e.g., during recovery), the daemon's SQLite connection points to the old
// (deleted) file, causing export to return incomplete/corrupt data.
// Using direct mode ensures we always read from the current database file.
//
// GH#984: Must use fallbackToDirectMode() instead of just closing daemon.
// When connected to daemon, PersistentPreRun skips store initialization.
// Just closing daemon leaves store=nil, causing "no database store available"
// errors in post-checkout hook's `bd sync --import-only`.
if daemonClient != nil {
debug.Logf("sync: forcing direct mode for consistency")
_ = daemonClient.Close()
daemonClient = nil
if err := fallbackToDirectMode("sync requires direct database access"); err != nil {
FatalError("failed to initialize direct mode: %v", err)
}
}
// Initialize local store after daemon disconnect.