Skip to content

Commit

Permalink
git-branch: rename config vars branch.<branch>.*, too
Browse files Browse the repository at this point in the history
When renaming a branch, the corresponding config section should
be renamed, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Dec 16, 2006
1 parent 0667fcf commit dc81c58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,16 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
goto rollback;
}

if (!strncmp(oldref, "refs/heads/", 11) &&
!strncmp(newref, "refs/heads/", 11)) {
char oldsection[1024], newsection[1024];

snprintf(oldsection, 1024, "branch.%s", oldref + 11);
snprintf(newsection, 1024, "branch.%s", newref + 11);
if (git_config_rename_section(oldsection, newsection) < 0)
return 1;
}

return 0;

rollback:
Expand Down
6 changes: 6 additions & 0 deletions t/t3200-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ test_expect_failure \
git-branch r &&
git-branch -m q r/q'

git-repo-config branch.s/s.dummy Hello

test_expect_success \
'git branch -m s/s s should work when s/t is deleted' \
'git-branch -l s/s &&
Expand All @@ -104,6 +106,10 @@ test_expect_success \
git-branch -m s/s s &&
test -f .git/logs/refs/heads/s'

test_expect_success 'config information was renamed, too' \
"test $(git-repo-config branch.s.dummy) = Hello &&
! git-repo-config branch.s/s/dummy"

test_expect_failure \
'git-branch -m u v should fail when the reflog for u is a symlink' \
'git-branch -l u &&
Expand Down

0 comments on commit dc81c58

Please sign in to comment.