Fix bd-191: bd sync --dry-run should not modify database
Skip auto-import when sync command is run with --dry-run flag to prevent database modifications during dry-run mode. Previously, autoImportIfNewer() would run in PersistentPreRun hook and modify the database even in dry-run, causing the JSONL file to become dirty. Amp-Thread-ID: https://ampcode.com/threads/T-1bc29344-0c59-4127-855d-860d1579ba0b Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -428,8 +428,21 @@ var rootCmd = &cobra.Command{
|
||||
|
||||
// Auto-import if JSONL is newer than DB (e.g., after git pull)
|
||||
// Skip for import command itself to avoid recursion
|
||||
// Skip if sync --dry-run to avoid modifying DB in dry-run mode (bd-191)
|
||||
if cmd.Name() != "import" && autoImportEnabled {
|
||||
autoImportIfNewer()
|
||||
// Check if this is sync command with --dry-run flag
|
||||
if cmd.Name() == "sync" {
|
||||
if dryRun, _ := cmd.Flags().GetBool("dry-run"); dryRun {
|
||||
// Skip auto-import in dry-run mode
|
||||
if os.Getenv("BD_DEBUG") != "" {
|
||||
fmt.Fprintf(os.Stderr, "Debug: auto-import skipped for sync --dry-run\n")
|
||||
}
|
||||
} else {
|
||||
autoImportIfNewer()
|
||||
}
|
||||
} else {
|
||||
autoImportIfNewer()
|
||||
}
|
||||
}
|
||||
},
|
||||
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
Reference in New Issue
Block a user