1. Stefan Saasen
  2. git

Commits

Junio C Hamano  committed 3734dbc Merge

Merge branch 'ef/checkout-empty' into maint

Running "git checkout" on an unborn branch used to corrupt HEAD
(regression in 1.7.10); this makes it error out.

By Erik Faye-Lund
* ef/checkout-empty:
checkout: do not corrupt HEAD on empty repo

  • Participants
  • Parent commits ea8c676, 8338f77
  • Branches master

Comments (0)

Files changed (2)

File builtin/checkout.c

View file
  • Ignore whitespace
 	if (opts.writeout_stage)
 		die(_("--ours/--theirs is incompatible with switching branches."));
 
-	if (!new.commit) {
+	if (!new.commit && opts.new_branch) {
 		unsigned char rev[20];
 		int flag;
 

File t/t2015-checkout-unborn.sh

View file
  • Ignore whitespace
 	test_cmp expect actual
 '
 
+test_expect_success 'checking out in a newly created repo' '
+	test_create_repo empty &&
+	(
+		cd empty &&
+		git symbolic-ref HEAD >expect &&
+		test_must_fail git checkout &&
+		git symbolic-ref HEAD >actual &&
+		test_cmp expect actual
+	)
+'
+
 test_done