diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-10-18 08:18:11 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-10-18 08:18:11 -0700 |
commit | a38bb0cc0fc98bf868ad48dc11d229addcca586c (patch) | |
tree | 5bd66906929bdadf42cd10522b1e71f9dc864654 /builtin-checkout.c | |
parent | 3b1eb124932772daee09419a581d418ea2d50045 (diff) | |
parent | 352eadc40024b141e1295693654ec20cc123844f (diff) | |
download | git-a38bb0cc0fc98bf868ad48dc11d229addcca586c.tar.gz |
Merge branch 'db/maint-checkout-b' into maint
* db/maint-checkout-b:
Check early that a new branch is new and valid
Diffstat (limited to 'builtin-checkout.c')
-rw-r--r-- | builtin-checkout.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c index c4fc2b2c56..1deda927cd 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -565,6 +565,18 @@ no_reference: return checkout_paths(source_tree, pathspec); } + if (opts.new_branch) { + struct strbuf buf; + strbuf_init(&buf, 0); + strbuf_addstr(&buf, "refs/heads/"); + strbuf_addstr(&buf, opts.new_branch); + if (!get_sha1(buf.buf, rev)) + die("git checkout: branch %s already exists", opts.new_branch); + if (check_ref_format(buf.buf)) + die("git checkout: we do not like '%s' as a branch name.", opts.new_branch); + strbuf_release(&buf); + } + if (new.name && !new.commit) { die("Cannot switch branch to a non-commit."); } |