diff options
author | Junio C Hamano <gitster@pobox.com> | 2017-11-28 04:41:49 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-11-28 04:41:49 (GMT) |
commit | 16169285f1e63f6a3d9ec10e48f55d6825d3156b (patch) | |
tree | ddcde546556a9bd2a5d4cce6daca273edc30963c /builtin | |
parent | 5f9953d2c365bffed6f9ee0c6966556bd4d7e2f4 (diff) | |
parent | 662a4c8a097248a3c08a671866ecf37743f3ca4d (diff) | |
download | git-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 'builtin')
-rw-r--r-- | builtin/branch.c | 11 | ||||
-rw-r--r-- | builtin/checkout.c | 10 |
2 files changed, 9 insertions, 12 deletions
diff --git a/builtin/branch.c b/builtin/branch.c index 33fd5fc..5fc57cd 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -463,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) @@ -487,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); @@ -793,9 +793,6 @@ int cmd_branch(int argc, const char **argv, const char *prefix) } else if (argc > 0 && argc <= 2) { struct branch *branch = branch_get(argv[0]); - if (!strcmp(argv[0], "HEAD")) - die(_("it does not make sense to create 'HEAD' manually")); - if (!branch) die(_("no such branch '%s'"), argv[0]); diff --git a/builtin/checkout.c b/builtin/checkout.c index 7d8bcc3..3faae382 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1287,11 +1287,11 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) if (opts.new_branch) { struct strbuf buf = STRBUF_INIT; - opts.branch_exists = - validate_new_branchname(opts.new_branch, &buf, - !!opts.new_branch_force, - !!opts.new_branch_force); - + if (opts.new_branch_force) + opts.branch_exists = validate_branchname(opts.new_branch, &buf); + else + opts.branch_exists = + validate_new_branchname(opts.new_branch, &buf, 0); strbuf_release(&buf); } |