commit 3bd303dcd4a45549c98b8c9f16e60e4db60255c8 Author: Jonas Fonseca Date: Wed Oct 17 02:21:25 2007 +0200 When renaming config sections delete conflicting sections The old behavior of keeping config sections matching the new name caused problems leading to warnings being emitted by git-remote when renaming branches where information about tracked remote branches differed. To fix this any config sections that will conflict with the new name are removed from the config file. Update test to check for this. Signed-off-by: Jonas Fonseca ~/src/git#next > git checkout -b test madcoder/next Branch test set up to track remote branch refs/remotes/madcoder/next. Switched to a new branch "test" ~/src/git#test > git checkout -b test2 spearce/next Branch test2 set up to track remote branch refs/remotes/spearce/next. Switched to a new branch "test2" ~/src/git#test2 > git branch -M test ~/src/git#test2 > cp .git/config .git/config+ ~/src/git#test2 > git branch -M test ~/src/git#test > diff -u .git/config{+,} --- .git/config+ 2007-10-17 02:01:21.000000000 +0200 +++ .git/config 2007-10-17 02:01:32.000000000 +0200 @@ -31,8 +31,5 @@ remote = spearce merge = refs/heads/next [branch "test"] - remote = madcoder - merge = refs/heads/next -[branch "test2"] remote = spearce merge = refs/heads/next diff --git a/config.c b/config.c index dc3148d..578849a 100644 --- a/config.c +++ b/config.c @@ -1013,6 +1013,14 @@ int git_config_rename_section(const char *old_name, const char *new_name) ; /* do nothing */ if (buf[i] == '[') { /* it's a section */ + remove = 0; + if (new_name != NULL + && section_name_match (&buf[i+1], new_name)) { + /* Remove any existing occurences of the + * new section. */ + remove = 1; + continue; + } if (section_name_match (&buf[i+1], old_name)) { ret++; if (new_name == NULL) { @@ -1026,7 +1034,6 @@ int git_config_rename_section(const char *old_name, const char *new_name) } continue; } - remove = 0; } if (remove) continue; diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 1d2bf2c..63b969e 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -419,6 +419,23 @@ EOF test_expect_success "section was removed properly" \ "git diff -u expect .git/config" +cat > .git/config << EOF +[branch "new-name"] + x = 1 +[branch "old-name"] + y = 1 +EOF + +test_expect_success "rename and remove old section" \ + 'git config --rename-section branch.old-name branch.new-name' + +cat > expect << EOF +[branch "new-name"] + y = 1 +EOF + +test_expect_success "rename and remove succeeded" "git diff expect .git/config" + rm .git/config cat > expect << EOF