mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-02 19:39:56 -05:00
Merge pull request #9401 from dolthub/macneale4-claude/issue-8039
Renaming default branch results in updating local config.
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqlserver"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/config"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
@@ -195,6 +196,19 @@ func renameBranch(ctx *sql.Context, dbData env.DbData[*sql.Context], apr *argpar
|
||||
}
|
||||
}
|
||||
|
||||
// Update init.defaultbranch config if the renamed branch was the default branch
|
||||
doltConfig := loadConfig(ctx)
|
||||
currentDefaultBranch := doltConfig.GetStringOrDefault(config.InitBranchName, "")
|
||||
if currentDefaultBranch == oldBranchName {
|
||||
// Get the local config for writing
|
||||
if localConfig, ok := doltConfig.GetConfig(env.LocalConfig); ok {
|
||||
err = localConfig.SetStrings(map[string]string{config.InitBranchName: newBranchName})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update init.defaultbranch config: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -300,3 +300,57 @@ teardown() {
|
||||
[ $status -eq "1" ]
|
||||
[[ "$output" =~ "is an invalid branch name" ]] || false
|
||||
}
|
||||
|
||||
@test "branch: renaming default branch should update init.defaultbranch config" {
|
||||
# Set up initial default branch config
|
||||
dolt config --local --add init.defaultbranch main
|
||||
|
||||
# Verify initial configuration
|
||||
run dolt config --local --get init.defaultbranch
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "main" ]] || false
|
||||
|
||||
# Rename the default branch using SQL function
|
||||
dolt sql -q "CALL DOLT_BRANCH('-m', 'main', 'altmain')"
|
||||
|
||||
# Verify the branch was renamed
|
||||
run dolt branch --show-current
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "altmain" ]] || false
|
||||
|
||||
# The init.defaultbranch config should be updated when the default branch is renamed
|
||||
run dolt config --local --get init.defaultbranch
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "altmain" ]] || false
|
||||
}
|
||||
|
||||
@test "branch: renaming non-default branch should not affect init.defaultbranch config" {
|
||||
# Set up initial default branch config
|
||||
dolt config --local --add init.defaultbranch main
|
||||
|
||||
# Create a non-default branch
|
||||
dolt sql -q "CALL DOLT_BRANCH('feature')"
|
||||
|
||||
# Verify initial configuration
|
||||
run dolt config --local --get init.defaultbranch
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "main" ]] || false
|
||||
|
||||
# Rename the non-default branch using SQL function
|
||||
dolt sql -q "CALL DOLT_BRANCH('-m', 'feature', 'newfeature')"
|
||||
|
||||
# Verify the branch was renamed
|
||||
run dolt branch
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "newfeature" ]] || false
|
||||
|
||||
# Verify the old branch name is gone
|
||||
run dolt sql -r csv -q "select count(*) from dolt_branches where name='feature';"
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "0" ]] || false
|
||||
|
||||
# The init.defaultbranch config should remain unchanged when a non-default branch is renamed
|
||||
run dolt config --local --get init.defaultbranch
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "main" ]] || false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user