]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/branch.c
branch: split validate_new_branchname() into two
[thirdparty/git.git] / builtin / branch.c
index 89e34e9ceb171412b9d36c6d2e01b929f1518e29..e5bbfb4a171fcacd92ca9614dbcd0f97627d8c77 100644 (file)
@@ -217,7 +217,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                if (!head_rev)
                        die(_("Couldn't look up commit object for HEAD"));
        }
-       for (i = 0; i < argc; i++, strbuf_release(&bname)) {
+       for (i = 0; i < argc; i++, strbuf_reset(&bname)) {
                char *target = NULL;
                int flags = 0;
 
@@ -282,8 +282,9 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
        }
 
        free(name);
+       strbuf_release(&bname);
 
-       return(ret);
+       return ret;
 }
 
 static int calc_maxwidth(struct ref_array *refs, int remote_bonus)
@@ -462,7 +463,6 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
        struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;
        struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT;
        int recovery = 0;
-       int clobber_head_ok;
 
        if (!oldname) {
                if (copy)
@@ -486,9 +486,10 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
         * A command like "git branch -M currentbranch currentbranch" cannot
         * cause the worktree to become inconsistent with HEAD, so allow it.
         */
-       clobber_head_ok = !strcmp(oldname, newname);
-
-       validate_new_branchname(newname, &newref, force, clobber_head_ok);
+       if (!strcmp(oldname, newname))
+               validate_branchname(newname, &newref);
+       else
+               validate_new_branchname(newname, &newref, force);
 
        reject_rebase_or_bisect_branch(oldref.buf);
 
@@ -743,12 +744,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                else if (argc == 2)
                        copy_or_rename_branch(argv[0], argv[1], 0, rename > 1);
                else
-                       die(_("too many branches for a rename operation"));
+                       die(_("too many arguments for a rename operation"));
        } else if (new_upstream) {
                struct branch *branch = branch_get(argv[0]);
 
                if (argc > 1)
-                       die(_("too many branches to set new upstream"));
+                       die(_("too many arguments to set new upstream"));
 
                if (!branch) {
                        if (!argc || !strcmp(argv[0], "HEAD"))
@@ -771,7 +772,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                struct strbuf buf = STRBUF_INIT;
 
                if (argc > 1)
-                       die(_("too many branches to unset upstream"));
+                       die(_("too many arguments to unset upstream"));
 
                if (!branch) {
                        if (!argc || !strcmp(argv[0], "HEAD"))