1. Stefan Saasen
  2. git


Junio C Hamano  committed 9ea5c63 Merge

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

  • Participants
  • Parent commits bb3ed29, 8ced1aa
  • Branches master

Comments (0)

Files changed (2)

File builtin/checkout.c

View file
  • Ignore whitespace
 	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");

File t/t2017-checkout-orphan.sh

View file
  • Ignore whitespace
 	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