fix(init,import): preserve metadata.json and improve prefix detection
- bd init now preserves existing metadata.json settings instead of
overwriting with defaults (bd-zai)
- bd init detects existing JSONL filename (beads.jsonl vs issues.jsonl)
when creating new metadata.json
- bd import now correctly reports prefix source ("issues" vs "directory")
- bd import avoids using ".beads" as prefix when run from inside .beads/
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+12
-3
@@ -200,20 +200,29 @@ NOTE: Import requires direct database access and does not work with daemon mode.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if database needs initialization (prefix not set)
|
// Check if database needs initialization (prefix not set)
|
||||||
// Detect prefix from the imported issues
|
// Detect prefix from the imported issues (bd-8an fix)
|
||||||
initCtx := rootCtx
|
initCtx := rootCtx
|
||||||
configuredPrefix, err2 := store.GetConfig(initCtx, "issue_prefix")
|
configuredPrefix, err2 := store.GetConfig(initCtx, "issue_prefix")
|
||||||
if err2 != nil || strings.TrimSpace(configuredPrefix) == "" {
|
if err2 != nil || strings.TrimSpace(configuredPrefix) == "" {
|
||||||
// Database exists but not initialized - detect prefix from issues
|
// Database exists but not initialized - detect prefix from issues
|
||||||
detectedPrefix := detectPrefixFromIssues(allIssues)
|
detectedPrefix := detectPrefixFromIssues(allIssues)
|
||||||
|
prefixSource := "issues"
|
||||||
if detectedPrefix == "" {
|
if detectedPrefix == "" {
|
||||||
// No issues to import or couldn't detect prefix, use directory name
|
// No issues to import or couldn't detect prefix, use directory name
|
||||||
|
// But avoid using ".beads" as prefix - go up one level
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: failed to get current directory: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: failed to get current directory: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
detectedPrefix = filepath.Base(cwd)
|
dirName := filepath.Base(cwd)
|
||||||
|
if dirName == ".beads" || dirName == "beads" {
|
||||||
|
// Running from inside .beads/ - use parent directory
|
||||||
|
detectedPrefix = filepath.Base(filepath.Dir(cwd))
|
||||||
|
} else {
|
||||||
|
detectedPrefix = dirName
|
||||||
|
}
|
||||||
|
prefixSource = "directory"
|
||||||
}
|
}
|
||||||
detectedPrefix = strings.TrimRight(detectedPrefix, "-")
|
detectedPrefix = strings.TrimRight(detectedPrefix, "-")
|
||||||
|
|
||||||
@@ -222,7 +231,7 @@ NOTE: Import requires direct database access and does not work with daemon mode.
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "✓ Initialized database with prefix '%s' (detected from issues)\n", detectedPrefix)
|
fmt.Fprintf(os.Stderr, "✓ Initialized database with prefix '%s' (detected from %s)\n", detectedPrefix, prefixSource)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Phase 2: Use shared import logic
|
// Phase 2: Use shared import logic
|
||||||
|
|||||||
+23
-2
@@ -294,9 +294,30 @@ With --stealth: configures global git settings for invisible beads usage:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create metadata.json for database metadata
|
// Create or preserve metadata.json for database metadata (bd-zai fix)
|
||||||
if useLocalBeads {
|
if useLocalBeads {
|
||||||
cfg := configfile.DefaultConfig()
|
// First, check if metadata.json already exists
|
||||||
|
existingCfg, err := configfile.Load(localBeadsDir)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Warning: failed to load existing metadata.json: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var cfg *configfile.Config
|
||||||
|
if existingCfg != nil {
|
||||||
|
// Preserve existing config
|
||||||
|
cfg = existingCfg
|
||||||
|
} else {
|
||||||
|
// Create new config, detecting JSONL filename from existing files
|
||||||
|
cfg = configfile.DefaultConfig()
|
||||||
|
// Check if beads.jsonl exists but issues.jsonl doesn't (legacy)
|
||||||
|
issuesPath := filepath.Join(localBeadsDir, "issues.jsonl")
|
||||||
|
beadsPath := filepath.Join(localBeadsDir, "beads.jsonl")
|
||||||
|
if _, err := os.Stat(beadsPath); err == nil {
|
||||||
|
if _, err := os.Stat(issuesPath); os.IsNotExist(err) {
|
||||||
|
cfg.JSONLExport = "beads.jsonl" // Legacy filename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := cfg.Save(localBeadsDir); err != nil {
|
if err := cfg.Save(localBeadsDir); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Warning: failed to create metadata.json: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Warning: failed to create metadata.json: %v\n", err)
|
||||||
// Non-fatal - continue anyway
|
// Non-fatal - continue anyway
|
||||||
|
|||||||
Reference in New Issue
Block a user