diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-11-28 05:41:49 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-11-28 05:41:49 +0100 |
commit | 16169285f1e63f6a3d9ec10e48f55d6825d3156b (patch) | |
tree | ddcde546556a9bd2a5d4cce6daca273edc30963c /sha1_name.c | |
parent | RelNotes: the sixth batch for 2.16 (diff) | |
parent | builtin/branch: remove redundant check for HEAD (diff) | |
download | git-16169285f1e63f6a3d9ec10e48f55d6825d3156b.tar.xz git-16169285f1e63f6a3d9ec10e48f55d6825d3156b.zip |
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.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/sha1_name.c b/sha1_name.c index 9a2d5caf3b..611c7d24dd 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); } |