From 702f7f34a260ac89781d742f5241a8c4d0e43e25 Mon Sep 17 00:00:00 2001 From: Neil Macneale IV Date: Tue, 27 May 2025 15:11:49 -0700 Subject: [PATCH 1/4] Add test to reproduce remote tracking cleanup issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test reproduces GitHub issue #9169 where removing a remote does not properly clean up branch tracking information. After 'dolt remote remove origin', the status still shows tracking references to the removed remote. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- integration-tests/bats/remote-cmd.bats | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/integration-tests/bats/remote-cmd.bats b/integration-tests/bats/remote-cmd.bats index 58d0099be8..40b48abec5 100755 --- a/integration-tests/bats/remote-cmd.bats +++ b/integration-tests/bats/remote-cmd.bats @@ -75,3 +75,31 @@ teardown() { [[ "$output" =~ "only valid for aws remotes" ]] || false fi } + +@test "remote-cmd: remove origin and verify tracking is gone" { + mkdir remote_repo + mkdir initter + cd initter + dolt init + dolt remote add origin file://../remote_repo + dolt push origin main + cd ../ + rm -rf initter + + dolt clone file://remote_repo cloned_repo + cd cloned_repo + + # Verify we are tracking origin + run dolt status + [ "$status" -eq 0 ] + [[ "$output" =~ "Your branch is up to date with 'origin/main'" ]] || false + + # Remove the remote + dolt remote remove origin + + # Verify that the current branch is not tracking origin (because it doesn't exist) + run dolt status + [ "$status" -eq 0 ] + [[ ! "$output" =~ "origin" ]] || false + [[ ! "$output" =~ "Your branch is up to date with 'origin/main'" ]] || false +} From cace617fc1d8a4a708fa133c202c1a595098372b Mon Sep 17 00:00:00 2001 From: Neil Macneale IV Date: Tue, 27 May 2025 15:48:42 -0700 Subject: [PATCH 2/4] Fix remote tracking cleanup when removing remotes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When removing a remote via 'dolt remote remove', the remote refs and remote entry were properly cleaned up, but branch configurations that tracked the removed remote were not updated. This caused 'dolt status' to still show tracking information for the removed remote. The fix adds logic to the dolt_remote SQL procedure to: 1. Find all branch configurations that reference the removed remote 2. Update those configurations to clear the remote field while preserving the head reference 3. Then proceed with the normal remote removal This ensures that after removing a remote, branches no longer show tracking status for the non-existent remote. Fixes #9169 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../doltcore/sqle/dprocedures/dolt_remote.go | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_remote.go b/go/libraries/doltcore/sqle/dprocedures/dolt_remote.go index 4aff66eeb7..746405ee89 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_remote.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_remote.go @@ -141,5 +141,32 @@ func removeRemote(ctx *sql.Context, dbd env.DbData[*sql.Context], apr *argparser } } + // Remove branch configurations that reference the removed remote + branches, err := dbd.Rsr.GetBranches() + if err != nil { + return fmt.Errorf("failed to get branches: %w", err) + } + + var branchesToUpdate []string + branches.Iter(func(branchName string, config env.BranchConfig) bool { + if config.Remote == remote.Name { + branchesToUpdate = append(branchesToUpdate, branchName) + } + return true + }) + + // Clear the remote tracking for these branches by updating their configs + for _, branchName := range branchesToUpdate { + currentConfig, _ := branches.Get(branchName) + updatedConfig := env.BranchConfig{ + Merge: currentConfig.Merge, + Remote: "", // Clear the remote reference + } + err = dbd.Rsw.UpdateBranch(branchName, updatedConfig) + if err != nil { + return fmt.Errorf("failed to update branch config for %s: %w", branchName, err) + } + } + return dbd.Rsw.RemoveRemote(ctx, remote.Name) } From 46cd9528418beccaa26417a7252bc0d8e91b529f Mon Sep 17 00:00:00 2001 From: macneale4 Date: Tue, 27 May 2025 23:00:28 +0000 Subject: [PATCH 3/4] [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh --- go/libraries/doltcore/sqle/dprocedures/dolt_remote.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_remote.go b/go/libraries/doltcore/sqle/dprocedures/dolt_remote.go index 746405ee89..b9c8dc1d53 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_remote.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_remote.go @@ -146,7 +146,7 @@ func removeRemote(ctx *sql.Context, dbd env.DbData[*sql.Context], apr *argparser if err != nil { return fmt.Errorf("failed to get branches: %w", err) } - + var branchesToUpdate []string branches.Iter(func(branchName string, config env.BranchConfig) bool { if config.Remote == remote.Name { @@ -154,7 +154,7 @@ func removeRemote(ctx *sql.Context, dbd env.DbData[*sql.Context], apr *argparser } return true }) - + // Clear the remote tracking for these branches by updating their configs for _, branchName := range branchesToUpdate { currentConfig, _ := branches.Get(branchName) From cfbcbf8d03249c984d59003e01e9d926a1a257d3 Mon Sep 17 00:00:00 2001 From: Neil Macneale IV Date: Wed, 28 May 2025 12:45:28 -0700 Subject: [PATCH 4/4] Make test more complete --- integration-tests/bats/remote-cmd.bats | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/integration-tests/bats/remote-cmd.bats b/integration-tests/bats/remote-cmd.bats index 40b48abec5..04061b67a6 100755 --- a/integration-tests/bats/remote-cmd.bats +++ b/integration-tests/bats/remote-cmd.bats @@ -93,6 +93,8 @@ teardown() { run dolt status [ "$status" -eq 0 ] [[ "$output" =~ "Your branch is up to date with 'origin/main'" ]] || false + + grep 'origin' .dolt/repo_state.json # Remove the remote dolt remote remove origin @@ -102,4 +104,7 @@ teardown() { [ "$status" -eq 0 ] [[ ! "$output" =~ "origin" ]] || false [[ ! "$output" =~ "Your branch is up to date with 'origin/main'" ]] || false + + run grep -q 'origin' .dolt/repo_state.json + [ "$status" -eq 1 ] }