Merge pull request #9256 from dolthub/macneale/claud-remote-cleanup

remote cleanup
This commit is contained in:
Neil Macneale IV
2025-05-28 13:25:25 -07:00
committed by GitHub
2 changed files with 60 additions and 0 deletions

View File

@@ -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)
}

View File

@@ -75,3 +75,36 @@ 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
grep 'origin' .dolt/repo_state.json
# 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
run grep -q 'origin' .dolt/repo_state.json
[ "$status" -eq 1 ]
}