summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-11-28 04:41:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-28 04:41:49 (GMT)
commit16169285f1e63f6a3d9ec10e48f55d6825d3156b (patch)
treeddcde546556a9bd2a5d4cce6daca273edc30963c /sha1_name.c
parent5f9953d2c365bffed6f9ee0c6966556bd4d7e2f4 (diff)
parent662a4c8a097248a3c08a671866ecf37743f3ca4d (diff)
downloadgit-16169285f1e63f6a3d9ec10e48f55d6825d3156b.zip
git-16169285f1e63f6a3d9ec10e48f55d6825d3156b.tar.gz
git-16169285f1e63f6a3d9ec10e48f55d6825d3156b.tar.bz2
Merge branch 'jc/branch-name-sanity'
"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()
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 9a2d5ca..611c7d2 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1438,9 +1438,19 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
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);
}