Add warning for multiple databases in directory hierarchy (bd-75)
- Implement FindAllDatabases() to scan hierarchy for all .beads directories - Add DatabaseInfo struct with path, beads dir, and issue count - Add warnMultipleDatabases() with formatted warning display - Show active database with ▶ marker and issue counts - Add comprehensive tests for multi-database detection - Document warning and solutions in TROUBLESHOOTING.md - Prevent confusion and database pollution from accidental duplicates Amp-Thread-ID: https://ampcode.com/threads/T-4941975f-2686-40d0-bc12-aabf38a05890 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -394,6 +394,9 @@ var rootCmd = &cobra.Command{
|
||||
storeActive = true
|
||||
storeMutex.Unlock()
|
||||
|
||||
// Warn if multiple databases detected in directory hierarchy
|
||||
warnMultipleDatabases(dbPath)
|
||||
|
||||
// Check for version mismatch (warn if binary is older than DB)
|
||||
checkVersionMismatch()
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/steveyegge/beads"
|
||||
)
|
||||
|
||||
// isGitWorktree detects if the current directory is in a git worktree
|
||||
@@ -91,3 +93,55 @@ func truncateForBox(path string, maxLen int) string {
|
||||
// Truncate with ellipsis
|
||||
return "..." + path[len(path)-(maxLen-3):]
|
||||
}
|
||||
|
||||
// warnMultipleDatabases prints a warning if multiple .beads databases exist
|
||||
// in the directory hierarchy, to prevent confusion and database pollution
|
||||
func warnMultipleDatabases(currentDB string) {
|
||||
databases := beads.FindAllDatabases()
|
||||
if len(databases) <= 1 {
|
||||
return // Only one database found, no warning needed
|
||||
}
|
||||
|
||||
// Find which database is active
|
||||
activeIdx := -1
|
||||
for i, db := range databases {
|
||||
if db.Path == currentDB {
|
||||
activeIdx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stderr)
|
||||
fmt.Fprintln(os.Stderr, "╔══════════════════════════════════════════════════════════════════════════╗")
|
||||
fmt.Fprintf(os.Stderr, "║ WARNING: %d beads databases detected in directory hierarchy ║\n", len(databases))
|
||||
fmt.Fprintln(os.Stderr, "╠══════════════════════════════════════════════════════════════════════════╣")
|
||||
fmt.Fprintln(os.Stderr, "║ Multiple databases can cause confusion and database pollution. ║")
|
||||
fmt.Fprintln(os.Stderr, "║ ║")
|
||||
|
||||
for i, db := range databases {
|
||||
isActive := (i == activeIdx)
|
||||
issueInfo := ""
|
||||
if db.IssueCount >= 0 {
|
||||
issueInfo = fmt.Sprintf(" (%d issues)", db.IssueCount)
|
||||
}
|
||||
|
||||
marker := " "
|
||||
if isActive {
|
||||
marker = "▶"
|
||||
}
|
||||
|
||||
line := fmt.Sprintf("%s %s%s", marker, db.BeadsDir, issueInfo)
|
||||
fmt.Fprintf(os.Stderr, "║ %-72s ║\n", truncateForBox(line, 72))
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stderr, "║ ║")
|
||||
if activeIdx == 0 {
|
||||
fmt.Fprintln(os.Stderr, "║ Currently using the closest database (▶). This is usually correct. ║")
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, "║ WARNING: Not using the closest database! Check your BEADS_DB setting. ║")
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "║ ║")
|
||||
fmt.Fprintln(os.Stderr, "║ RECOMMENDED: Consolidate or remove unused databases to avoid confusion. ║")
|
||||
fmt.Fprintln(os.Stderr, "╚══════════════════════════════════════════════════════════════════════════╝")
|
||||
fmt.Fprintln(os.Stderr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user