fix(beads): stop searching upward when .beads found (gt-bzd)
In multi-workspace setups like Gas Town, nested .beads directories are intentional and separate: - Town level: ~/gt/.beads - Rig level: ~/gt/gastown/.beads Previously, FindAllDatabases() walked up the entire directory tree and warned about "multiple databases detected" even though these are unrelated beads instances for different scopes. Now FindAllDatabases() stops as soon as it finds the first (closest) .beads directory. Parent directories are out of scope. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -528,10 +528,11 @@ func findDatabaseInTree() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// FindAllDatabases scans the directory hierarchy for all .beads directories
|
||||
// Returns a slice of DatabaseInfo for each database found, starting from the
|
||||
// closest to CWD (most relevant) to the furthest (least relevant).
|
||||
// Stops at the git repository root to avoid finding unrelated databases (bd-c8x).
|
||||
// FindAllDatabases scans the directory hierarchy for the closest .beads directory.
|
||||
// Returns a slice with at most one DatabaseInfo - the closest database to CWD.
|
||||
// Stops searching upward as soon as a .beads directory is found (gt-bzd),
|
||||
// because in multi-workspace setups (like Gas Town), nested .beads directories
|
||||
// are intentional and separate - parent directories are out of scope.
|
||||
// Redirect files are supported: if a .beads/redirect file exists, its contents
|
||||
// are used as the actual .beads directory path.
|
||||
func FindAllDatabases() []DatabaseInfo {
|
||||
@@ -594,6 +595,10 @@ func FindAllDatabases() []DatabaseInfo {
|
||||
BeadsDir: beadsDir,
|
||||
IssueCount: issueCount,
|
||||
})
|
||||
|
||||
// Stop searching upward - the closest .beads is the one to use (gt-bzd)
|
||||
// Parent directories are out of scope in multi-workspace setups
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,26 +63,23 @@ func TestFindAllDatabases(t *testing.T) {
|
||||
|
||||
databases := FindAllDatabases()
|
||||
|
||||
// Should find both databases, with project1 first (closest)
|
||||
if len(databases) != 2 {
|
||||
t.Fatalf("expected 2 databases, got %d", len(databases))
|
||||
// Should find only the closest database (gt-bzd: stop searching when .beads found)
|
||||
// Parent .beads directories are out of scope in multi-workspace setups like Gas Town
|
||||
if len(databases) != 1 {
|
||||
t.Fatalf("expected 1 database (closest only), got %d", len(databases))
|
||||
}
|
||||
|
||||
// First database should be project1 (closest to CWD)
|
||||
// Database should be project1 (closest to CWD)
|
||||
if databases[0].Path != project1DB {
|
||||
t.Errorf("expected first database to be %s, got %s", project1DB, databases[0].Path)
|
||||
t.Errorf("expected database to be %s, got %s", project1DB, databases[0].Path)
|
||||
}
|
||||
if databases[0].BeadsDir != project1Beads {
|
||||
t.Errorf("expected first beads dir to be %s, got %s", project1Beads, databases[0].BeadsDir)
|
||||
t.Errorf("expected beads dir to be %s, got %s", project1Beads, databases[0].BeadsDir)
|
||||
}
|
||||
|
||||
// Second database should be root (furthest from CWD)
|
||||
if databases[1].Path != rootDB {
|
||||
t.Errorf("expected second database to be %s, got %s", rootDB, databases[1].Path)
|
||||
}
|
||||
if databases[1].BeadsDir != rootBeads {
|
||||
t.Errorf("expected second beads dir to be %s, got %s", rootBeads, databases[1].BeadsDir)
|
||||
}
|
||||
// Root database should NOT be found - it's out of scope (parent of closest .beads)
|
||||
_ = rootDB // referenced but not expected in results
|
||||
_ = rootBeads // referenced but not expected in results
|
||||
}
|
||||
|
||||
func TestFindAllDatabases_Single(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user