From 8ced1aa08f9e1798b2b3fec41a0598ef79b477fe Mon Sep 17 00:00:00 2001 From: Chris Webb Date: Tue, 26 Jun 2012 16:06:42 +0100 Subject: git-checkout: disallow --detach on unborn branch abe199808c (git checkout -b: allow switching out of an unborn branch) introduced a bug demonstrated by git checkout --orphan foo git checkout --detach git symbolic-ref HEAD which gives 'refs/heads/(null)'. This happens because we strbuf_addf(&branch_ref, "refs/heads/%s", opts->new_branch) when opts->new_branch can be NULL for --detach. Catch and forbid this case, adding a test to t2017 to catch it in future. Signed-off-by: Chris Webb Signed-off-by: Junio C Hamano --- builtin/checkout.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin') diff --git a/builtin/checkout.c b/builtin/checkout.c index b76e2c0451..a94b553d05 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); -- cgit v1.2.3