Merge branch 'jc/branch-name-sanity'
authorJunio C Hamano <gitster@pobox.com>
Tue, 28 Nov 2017 04:41:49 +0000 (13:41 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Nov 2017 04:41:49 +0000 (13:41 +0900)
"git branch" and "git checkout -b" are now forbidden from creating
a branch whose name is "HEAD".

* jc/branch-name-sanity:
builtin/branch: remove redundant check for HEAD
branch: correctly reject refs/heads/{-dash,HEAD}
branch: split validate_new_branchname() into two
branch: streamline "attr_only" handling in validate_new_branchname()

1  2 
branch.c
builtin/branch.c
builtin/checkout.c
sha1_name.c
diff --cc branch.c
Simple merge
Simple merge
Simple merge
diff --cc sha1_name.c
index 9a2d5caf3b785ec629fcbc2325cd63e0ef72cf57,67961d6e47b67eac4372cbe5ffb37fa3d97c5861..611c7d24ddee678470ba74cb3c2ca669a778b44a
@@@ -1434,13 -1331,20 +1434,23 @@@ void strbuf_branchname(struct strbuf *s
  
  int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
  {
 -      strbuf_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
 +      if (startup_info->have_repository)
 +              strbuf_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
 +      else
 +              strbuf_addstr(sb, name);
-       if (name[0] == '-')
-               return -1;
+       /*
+        * This splice must be done even if we end up rejecting the
+        * name; builtin/branch.c::copy_or_rename_branch() still wants
+        * to see what the name expanded to so that "branch -m" can be
+        * used as a tool to correct earlier mistakes.
+        */
        strbuf_splice(sb, 0, 0, "refs/heads/", 11);
+       if (*name == '-' ||
+           !strcmp(sb->buf, "refs/heads/HEAD"))
+               return -1;
        return check_refname_format(sb->buf, 0);
  }