From: Junio C Hamano Date: Sat, 18 Oct 2008 15:18:11 +0000 (-0700) Subject: Merge branch 'db/maint-checkout-b' into maint X-Git-Tag: v1.6.0.3~6 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/a38bb0cc0fc98bf868ad48dc11d229addcca586c?hp=-c Merge branch 'db/maint-checkout-b' into maint * db/maint-checkout-b: Check early that a new branch is new and valid --- a38bb0cc0fc98bf868ad48dc11d229addcca586c diff --combined builtin-checkout.c index c4fc2b2c56,1ee23468ff..1deda927cd --- a/builtin-checkout.c +++ b/builtin-checkout.c @@@ -328,7 -328,7 +328,7 @@@ static int merge_working_tree(struct ch commit_locked_index(lock_file)) die("unable to write new index file"); - if (!opts->force) + if (!opts->force && !opts->quiet) show_local_changes(&new->commit->object); return 0; @@@ -565,6 -565,18 +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."); }