Code

pack-objects: pass fullname down to add_object_entry()
[git.git] / builtin-branch.c
index a4494ee337d70a400664e529e84f90d475a03b92..a5b6bbef6e903991cf70fd5978f5f89c48c60fb5 100644 (file)
@@ -462,7 +462,7 @@ static void create_branch(const char *name, const char *start_name,
                die("Not a valid branch point: '%s'.", start_name);
        hashcpy(sha1, commit->object.sha1);
 
-       lock = lock_any_ref_for_update(ref, NULL);
+       lock = lock_any_ref_for_update(ref, NULL, 0);
        if (!lock)
                die("Failed to lock ref for update: %s.", strerror(errno));
 
@@ -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.");
@@ -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)
@@ -617,9 +623,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
            (rename && force_create))
                usage(builtin_branch_usage);
 
-       head = xstrdup(resolve_ref("HEAD", head_sha1, 0, NULL));
+       head = resolve_ref("HEAD", head_sha1, 0, NULL);
        if (!head)
                die("Failed to resolve HEAD as a valid ref.");
+       head = xstrdup(head);
        if (!strcmp(head, "HEAD")) {
                detached = 1;
        }