fix(redirect): follow redirect when creating database (GH#bd-0qel)
When bd runs with --no-daemon or during init in a directory that has a .beads/redirect file, it now correctly follows the redirect to create the database in the target location instead of locally. The bug occurred because: 1. init.go hardcoded .beads/beads.db without checking for redirects 2. main.go's fallback path for auto-bootstrap also used local .beads Both code paths now call beads.FollowRedirect() to resolve the correct .beads directory before constructing the database path. Added TestInitWithRedirect to verify the fix. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -532,7 +532,16 @@ var rootCmd = &cobra.Command{
|
||||
// Invariant: dbPath must always be absolute for filepath.Rel() compatibility
|
||||
// in daemon sync-branch code path. Use CanonicalizePath for OS-agnostic
|
||||
// handling (symlinks, case normalization on macOS).
|
||||
dbPath = utils.CanonicalizePath(filepath.Join(".beads", beads.CanonicalDatabaseName))
|
||||
//
|
||||
// IMPORTANT: Use FindBeadsDir() to get the correct .beads directory,
|
||||
// which follows redirect files. Without this, a redirected .beads
|
||||
// would create a local database instead of using the redirect target.
|
||||
// (GH#bd-0qel)
|
||||
targetBeadsDir := beads.FindBeadsDir()
|
||||
if targetBeadsDir == "" {
|
||||
targetBeadsDir = ".beads"
|
||||
}
|
||||
dbPath = utils.CanonicalizePath(filepath.Join(targetBeadsDir, beads.CanonicalDatabaseName))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user