diff options
-rw-r--r-- | builtin/checkout.c | 2 | ||||
-rwxr-xr-x | t/t2017-checkout-orphan.sh | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index b76e2c045..a94b553d0 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -921,6 +921,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); diff --git a/t/t2017-checkout-orphan.sh b/t/t2017-checkout-orphan.sh index 0e3b8582f..655f278c5 100755 --- a/t/t2017-checkout-orphan.sh +++ b/t/t2017-checkout-orphan.sh @@ -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 |