Skip to content

Commit

Permalink
Make builtin-branch.c handle the git config file
Browse files Browse the repository at this point in the history
This moves the knowledge about .git/config usage out of refs.c and into
builtin-branch.c instead, which allows git-branch to update HEAD to point
at the moved branch before attempting to update the config file. It also
allows git-branch to exit with an error code if updating the config file
should fail.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Lars Hjemli authored and Junio C Hamano committed Apr 6, 2007
1 parent d26f9fe commit 19eba15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 6 additions & 0 deletions builtin-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)
{
char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100];
unsigned char sha1[20];
char oldsection[PATH_MAX], newsection[PATH_MAX];

if (!oldname)
die("cannot rename the current branch while not on any.");
Expand Down Expand Up @@ -521,6 +522,11 @@ static void rename_branch(const char *oldname, const char *newname, int force)
/* no need to pass logmsg here as HEAD didn't really move */
if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL))
die("Branch renamed to %s, but HEAD is not updated!", newname);

snprintf(oldsection, sizeof(oldsection), "branch.%s", oldref + 11);
snprintf(newsection, sizeof(newsection), "branch.%s", newref + 11);
if (git_config_rename_section(oldsection, newsection) < 0)
die("Branch is renamed, but update of config-file failed");
}

int cmd_branch(int argc, const char **argv, const char *prefix)
Expand Down
10 changes: 0 additions & 10 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,16 +828,6 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
goto rollback;
}

if (!prefixcmp(oldref, "refs/heads/") &&
!prefixcmp(newref, "refs/heads/")) {
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)
error("unable to update config-file");
}

return 0;

rollback:
Expand Down

0 comments on commit 19eba15

Please sign in to comment.