Merge branch 'cw/no-detaching-an-unborn' into maint

"git checkout --detach", when you are still on an unborn branch,
should be forbidden, but it wasn't.

* cw/no-detaching-an-unborn:
  git-checkout: disallow --detach on unborn branch
This commit is contained in:
Junio C Hamano 2012-07-22 13:00:31 -07:00
commit 9ea5c632da
2 changed files with 8 additions and 0 deletions

View file

@ -915,6 +915,8 @@ static int switch_unborn_to_new_branch(struct checkout_opts *opts)
int status;
struct strbuf branch_ref = STRBUF_INIT;
if (!opts->new_branch)
die(_("You are on a branch yet to be born"));
strbuf_addf(&branch_ref, "refs/heads/%s", opts->new_branch);
status = create_symref("HEAD", branch_ref.buf, "checkout -b");
strbuf_release(&branch_ref);

View file

@ -116,4 +116,10 @@ test_expect_success '--orphan refuses to switch if a merge is needed' '
git reset --hard
'
test_expect_success 'cannot --detach on an unborn branch' '
git checkout master &&
git checkout --orphan new &&
test_must_fail git checkout --detach
'
test_done