Skip to content

Commit 491c276

Browse files
steveyeggeclaude
andcommitted
fix: use CLIDir for dolt remote operations instead of root Path (GH#2306, GH#2311)
Remote add/list/remove in cmd/bd/dolt.go used st.Path() which returns .beads/dolt/ (the server root), not .beads/dolt/{database}/ where the actual database lives. This caused remotes to be registered in the wrong directory, making push/pull fail with "remote not found" or target the empty root database. Exported cliDir() as CLIDir() and switched all three remote operations to use it, matching the behavior already used by Push() and Pull(). Reported-by: Shybko (GH#2306) Reported-by: tha-hammer (GH#2311) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9dc875a commit 491c276

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

cmd/bd/dolt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ var doltRemoteAddCmd = &cobra.Command{
555555
os.Exit(1)
556556
}
557557
name, url := args[0], args[1]
558-
dbPath := st.Path()
558+
dbPath := st.CLIDir()
559559

560560
// Check existing remotes on both surfaces
561561
sqlRemotes, _ := st.ListRemotes(ctx)
@@ -640,7 +640,7 @@ var doltRemoteListCmd = &cobra.Command{
640640
fmt.Fprintf(os.Stderr, "Error: no store available\n")
641641
os.Exit(1)
642642
}
643-
dbPath := st.Path()
643+
dbPath := st.CLIDir()
644644

645645
sqlRemotes, sqlErr := st.ListRemotes(ctx)
646646
if sqlErr != nil {
@@ -751,7 +751,7 @@ var doltRemoteRemoveCmd = &cobra.Command{
751751
os.Exit(1)
752752
}
753753
name := args[0]
754-
dbPath := st.Path()
754+
dbPath := st.CLIDir()
755755

756756
// Check both surfaces for conflicts
757757
sqlRemotes, _ := st.ListRemotes(ctx)

internal/storage/dolt/federation.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ func (s *DoltStore) isPeerGitProtocolRemote(ctx context.Context, peer string) bo
278278
if !doltutil.IsGitProtocolURL(r.URL) {
279279
return false
280280
}
281-
return s.cliDir() != "" && doltutil.FindCLIRemote(s.cliDir(), peer) != ""
281+
return s.CLIDir() != "" && doltutil.FindCLIRemote(s.CLIDir(), peer) != ""
282282
}
283283
}
284284
}
285-
if s.cliDir() != "" {
286-
if url := doltutil.FindCLIRemote(s.cliDir(), peer); url != "" {
285+
if s.CLIDir() != "" {
286+
if url := doltutil.FindCLIRemote(s.CLIDir(), peer); url != "" {
287287
return doltutil.IsGitProtocolURL(url)
288288
}
289289
}
@@ -295,7 +295,7 @@ func (s *DoltStore) isPeerGitProtocolRemote(ctx context.Context, peer string) bo
295295
// Credentials are set on the subprocess environment only via cmd.Env.
296296
func (s *DoltStore) doltCLIPushToPeer(ctx context.Context, peer string, creds *remoteCredentials) error {
297297
cmd := exec.CommandContext(ctx, "dolt", "push", peer, s.branch) // #nosec G204 -- fixed command with validated peer/branch
298-
cmd.Dir = s.cliDir()
298+
cmd.Dir = s.CLIDir()
299299
creds.applyToCmd(cmd)
300300
out, err := cmd.CombinedOutput()
301301
if err != nil {
@@ -309,7 +309,7 @@ func (s *DoltStore) doltCLIPushToPeer(ctx context.Context, peer string, creds *r
309309
// Credentials are set on the subprocess environment only via cmd.Env.
310310
func (s *DoltStore) doltCLIPullFromPeer(ctx context.Context, peer string, creds *remoteCredentials) error {
311311
cmd := exec.CommandContext(ctx, "dolt", "pull", peer, s.branch) // #nosec G204 -- fixed command with validated peer/branch
312-
cmd.Dir = s.cliDir()
312+
cmd.Dir = s.CLIDir()
313313
creds.applyToCmd(cmd)
314314
out, err := cmd.CombinedOutput()
315315
if err != nil {
@@ -323,7 +323,7 @@ func (s *DoltStore) doltCLIPullFromPeer(ctx context.Context, peer string, creds
323323
// Credentials are set on the subprocess environment only via cmd.Env.
324324
func (s *DoltStore) doltCLIFetchFromPeer(ctx context.Context, peer string, creds *remoteCredentials) error {
325325
cmd := exec.CommandContext(ctx, "dolt", "fetch", peer) // #nosec G204 -- fixed command with validated peer
326-
cmd.Dir = s.cliDir()
326+
cmd.Dir = s.CLIDir()
327327
creds.applyToCmd(cmd)
328328
out, err := cmd.CombinedOutput()
329329
if err != nil {

internal/storage/dolt/store.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,9 @@ func (s *DoltStore) Path() string {
11721172
return s.dbPath
11731173
}
11741174

1175-
// cliDir returns the directory for dolt CLI operations (push/pull/remote/fetch).
1175+
// CLIDir returns the directory for dolt CLI operations (push/pull/remote/fetch).
11761176
// The actual database lives in a subdirectory of dbPath named after the database.
1177-
func (s *DoltStore) cliDir() string {
1177+
func (s *DoltStore) CLIDir() string {
11781178
if s.dbPath == "" {
11791179
return ""
11801180
}
@@ -1409,13 +1409,13 @@ func (s *DoltStore) isGitProtocolRemote(ctx context.Context) bool {
14091409
// Verify remote exists in CLI directory before routing to CLI push/pull.
14101410
// When the dolt sql-server is externally managed, remotes may exist only
14111411
// on the server's filesystem, not in the local dbPath.
1412-
return s.cliDir() != "" && doltutil.FindCLIRemote(s.cliDir(), s.remote) != ""
1412+
return s.CLIDir() != "" && doltutil.FindCLIRemote(s.CLIDir(), s.remote) != ""
14131413
}
14141414
}
14151415
}
14161416
// Fall back to CLI remotes (covers drift where remote exists only in filesystem)
1417-
if s.cliDir() != "" {
1418-
if url := doltutil.FindCLIRemote(s.cliDir(), s.remote); url != "" {
1417+
if s.CLIDir() != "" {
1418+
if url := doltutil.FindCLIRemote(s.CLIDir(), s.remote); url != "" {
14191419
return doltutil.IsGitProtocolURL(url)
14201420
}
14211421
}
@@ -1443,7 +1443,7 @@ func (s *DoltStore) doltCLIPush(ctx context.Context, force bool, creds *remoteCr
14431443
}
14441444
args = append(args, s.remote, s.branch)
14451445
cmd := exec.CommandContext(ctx, "dolt", args...) // #nosec G204 -- fixed command with validated remote/branch
1446-
cmd.Dir = s.cliDir()
1446+
cmd.Dir = s.CLIDir()
14471447
creds.applyToCmd(cmd)
14481448
out, err := cmd.CombinedOutput()
14491449
if err != nil {
@@ -1459,7 +1459,7 @@ func (s *DoltStore) doltCLIPull(ctx context.Context, creds *remoteCredentials) e
14591459
ctx, cancel := context.WithTimeout(ctx, cliExecTimeout)
14601460
defer cancel()
14611461
cmd := exec.CommandContext(ctx, "dolt", "pull", s.remote, s.branch) // #nosec G204 -- fixed command
1462-
cmd.Dir = s.cliDir()
1462+
cmd.Dir = s.CLIDir()
14631463
creds.applyToCmd(cmd)
14641464
out, err := cmd.CombinedOutput()
14651465
if err != nil {

0 commit comments

Comments
 (0)