git-shell: Add 'git-upload-archive' to allowed commands.
[gitweb.git] / builtin-branch.c
index 0df82bf96d7f06426ac0ff89f3410714257c20fd..ca81d725cbac618b7dbb351dc4fb8d3a7f8fef1b 100644 (file)
@@ -167,7 +167,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
                        ret = 1;
                } else {
                        struct strbuf buf = STRBUF_INIT;
-                       printf("Deleted %sbranch %s (%s).\n", remote,
+                       printf("Deleted %sbranch %s (was %s).\n", remote,
                               bname.buf,
                               find_unique_abbrev(sha1, DEFAULT_ABBREV));
                        strbuf_addf(&buf, "branch.%s", bname.buf);
@@ -464,18 +464,23 @@ static void rename_branch(const char *oldname, const char *newname, int force)
        struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;
        unsigned char sha1[20];
        struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT;
+       int recovery = 0;
 
        if (!oldname)
                die("cannot rename the current branch while not on any.");
 
-       strbuf_branchname(&oldref, oldname);
-       strbuf_splice(&oldref, 0, 0, "refs/heads/", 11);
-       if (check_ref_format(oldref.buf))
-               die("Invalid branch name: '%s'", oldname);
+       if (strbuf_check_branch_ref(&oldref, oldname)) {
+               /*
+                * Bad name --- this could be an attempt to rename a
+                * ref that we used to allow to be created by accident.
+                */
+               if (resolve_ref(oldref.buf, sha1, 1, NULL))
+                       recovery = 1;
+               else
+                       die("Invalid branch name: '%s'", oldname);
+       }
 
-       strbuf_branchname(&newref, newname);
-       strbuf_splice(&newref, 0, 0, "refs/heads/", 11);
-       if (check_ref_format(newref.buf))
+       if (strbuf_check_branch_ref(&newref, newname))
                die("Invalid branch name: '%s'", newname);
 
        if (resolve_ref(newref.buf, sha1, 1, NULL) && !force)
@@ -488,6 +493,9 @@ static void rename_branch(const char *oldname, const char *newname, int force)
                die("Branch rename failed");
        strbuf_release(&logmsg);
 
+       if (recovery)
+               warning("Renamed a misnamed branch '%s' away", oldref.buf + 11);
+
        /* no need to pass logmsg here as HEAD didn't really move */
        if (!strcmp(oldname, head) && create_symref("HEAD", newref.buf, NULL))
                die("Branch renamed to %s, but HEAD is not updated!", newname);