fix(staleness): auto-import on stale DB for read-only commands (bd-9dao) (#982)
When database is stale and a read-only command runs in --no-daemon mode, auto-import from JSONL instead of returning an error. This fixes `gt sling` failing with 'not a valid bead' after git pull. Root cause: `ensureDatabaseFresh` would return an error when DB was stale, but read-only commands like `bd show` should be able to auto-import and proceed rather than blocking the user. Changes: - Modify ensureDatabaseFresh to call autoImportIfNewer() when stale - Only error if --no-auto-import flag is explicitly set - Add comprehensive tests for all staleness scenarios Fixes: bd-9dao Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -43,7 +43,15 @@ func ensureDatabaseFresh(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Database is stale - refuse to operate
|
||||
// Database is stale - auto-import to refresh (bd-9dao fix)
|
||||
// For read-only commands running in --no-daemon mode, auto-import instead of
|
||||
// returning an error. This allows commands like `bd show` to work after git pull.
|
||||
if !noAutoImport {
|
||||
autoImportIfNewer()
|
||||
return nil
|
||||
}
|
||||
|
||||
// Auto-import is disabled, refuse to operate
|
||||
return fmt.Errorf(
|
||||
"Database out of sync with JSONL. Run 'bd sync --import-only' to fix.\n\n"+
|
||||
"The JSONL file has been updated (e.g., after 'git pull') but the database\n"+
|
||||
|
||||
Reference in New Issue
Block a user