Add bd sync --import-only flag and git pull integration test (bd-124, bd-125)

- Add --import-only flag to bd sync command for manual JSONL import after git pull
- Show import summary output instead of suppressing it
- Add comprehensive integration test for git pull sync scenario
- Test covers non-daemon auto-import and bd sync command
- Verify performance of import operations

Closes bd-123, bd-114, bd-124, bd-125, bd-136, bd-137

Amp-Thread-ID: https://ampcode.com/threads/T-7d8dc20f-baf2-4d1d-add1-57fa67028c15
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-26 12:37:46 -07:00
parent 8fe0586080
commit c91e83e993
4 changed files with 355 additions and 7 deletions

View File

@@ -28,7 +28,8 @@ var syncCmd = &cobra.Command{
This command wraps the entire git-based sync workflow for multi-device use.
Use --flush-only to just export pending changes to JSONL (useful for pre-commit hooks).`,
Use --flush-only to just export pending changes to JSONL (useful for pre-commit hooks).
Use --import-only to just import from JSONL (useful after git pull).`,
Run: func(cmd *cobra.Command, _ []string) {
ctx := context.Background()
@@ -38,6 +39,7 @@ Use --flush-only to just export pending changes to JSONL (useful for pre-commit
noPull, _ := cmd.Flags().GetBool("no-pull")
renameOnImport, _ := cmd.Flags().GetBool("rename-on-import")
flushOnly, _ := cmd.Flags().GetBool("flush-only")
importOnly, _ := cmd.Flags().GetBool("import-only")
// Find JSONL path
jsonlPath := findJSONLPath()
@@ -46,6 +48,21 @@ Use --flush-only to just export pending changes to JSONL (useful for pre-commit
os.Exit(1)
}
// If import-only mode, just import and exit
if importOnly {
if dryRun {
fmt.Println("→ [DRY RUN] Would import from JSONL")
} else {
fmt.Println("→ Importing from JSONL...")
if err := importFromJSONL(ctx, jsonlPath, renameOnImport); err != nil {
fmt.Fprintf(os.Stderr, "Error importing: %v\n", err)
os.Exit(1)
}
fmt.Println("✓ Import complete")
}
return
}
// If flush-only mode, just export and exit
if flushOnly {
if dryRun {
@@ -165,6 +182,7 @@ func init() {
syncCmd.Flags().Bool("no-pull", false, "Skip pulling from remote")
syncCmd.Flags().Bool("rename-on-import", false, "Rename imported issues to match database prefix (updates all references)")
syncCmd.Flags().Bool("flush-only", false, "Only export pending changes to JSONL (skip git operations)")
syncCmd.Flags().Bool("import-only", false, "Only import from JSONL (skip git operations, useful after git pull)")
rootCmd.AddCommand(syncCmd)
}
@@ -412,6 +430,11 @@ func importFromJSONL(ctx context.Context, jsonlPath string, renameOnImport bool)
if err != nil {
return fmt.Errorf("import failed: %w\n%s", err, output)
}
// Suppress output unless there's an error
// Show output (import command provides the summary)
if len(output) > 0 {
fmt.Print(string(output))
}
return nil
}