fix(init): add safety guard to prevent overwriting existing data

bd init now refuses when:
- JSONL file exists with >0 issues (fresh clone scenario)
- Database file already exists (already initialized)

Suggests `bd doctor --fix` for fresh clones and provides clear guidance.
Added --force flag to bypass the safety guard when needed.

Closes: bd-emg

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-28 22:15:13 -08:00
parent a34c56c43a
commit 3a4840169d
3 changed files with 197 additions and 78 deletions

View File

@@ -196,7 +196,7 @@ func TestInitAlreadyInitialized(t *testing.T) {
origDBPath := dbPath
defer func() { dbPath = origDBPath }()
dbPath = ""
tmpDir := t.TempDir()
originalWd, err := os.Getwd()
if err != nil {
@@ -215,11 +215,12 @@ func TestInitAlreadyInitialized(t *testing.T) {
t.Fatalf("First init failed: %v", err)
}
// Initialize again with same prefix - should succeed (overwrites)
rootCmd.SetArgs([]string{"init", "--prefix", "test", "--quiet"})
// Initialize again with same prefix and --force flag (bd-emg: safety guard)
// Without --force, init should refuse when database already exists
rootCmd.SetArgs([]string{"init", "--prefix", "test", "--quiet", "--force"})
if err := rootCmd.Execute(); err != nil {
t.Fatalf("Second init failed: %v", err)
t.Fatalf("Second init with --force failed: %v", err)
}
// Verify database still works (always beads.db now)