@matheusbsbs / matheus-bagliano / commits / 19eba1515a
Fork 0

Make builtin-branch.c handle the git config file

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>

Lars Hjemli committed Apr 6, 2007 at 14:13 UTC 19eba1515a7d3b0dac6d4ee73492d978c3c2149b
2 files changed +6 -10
builtin-branch.c
+6
@@ -493,6 +493,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)
493 {
494 char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100];
495 unsigned char sha1[20];
496 + char oldsection[PATH_MAX], newsection[PATH_MAX];
497
498 if (!oldname)
499 die("cannot rename the current branch while not on any.");
@@ -521,6 +522,11 @@ static void rename_branch(const char *oldname, const char *newname, int force)
522 /* no need to pass logmsg here as HEAD didn't really move */
523 if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL))
524 die("Branch renamed to %s, but HEAD is not updated!", newname);
525 +
526 + snprintf(oldsection, sizeof(oldsection), "branch.%s", oldref + 11);
527 + snprintf(newsection, sizeof(newsection), "branch.%s", newref + 11);
528 + if (git_config_rename_section(oldsection, newsection) < 0)
529 + die("Branch is renamed, but update of config-file failed");
530 }
531
532 int cmd_branch(int argc, const char **argv, const char *prefix)
refs.c
-10
@@ -828,16 +828,6 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
828 goto rollback;
829 }
830
831 - if (!prefixcmp(oldref, "refs/heads/") &&
832 - !prefixcmp(newref, "refs/heads/")) {
833 - char oldsection[1024], newsection[1024];
834 -
835 - snprintf(oldsection, 1024, "branch.%s", oldref + 11);
836 - snprintf(newsection, 1024, "branch.%s", newref + 11);
837 - if (git_config_rename_section(oldsection, newsection) < 0)
838 - error("unable to update config-file");
839 - }
840 -
831 return 0;
832
833 rollback: