Skip to content

Commit a735b79

Browse files
committed
Merge branch 'ef/checkout-empty'
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
2 parents d318a39 + 8338f77 commit a735b79

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
10921092
if (opts.writeout_stage)
10931093
die(_("--ours/--theirs is incompatible with switching branches."));
10941094

1095-
if (!new.commit) {
1095+
if (!new.commit && opts.new_branch) {
10961096
unsigned char rev[20];
10971097
int flag;
10981098

t/t2015-checkout-unborn.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,15 @@ test_expect_success 'checking out another branch from unborn state' '
4646
test_cmp expect actual
4747
'
4848

49+
test_expect_success 'checking out in a newly created repo' '
50+
test_create_repo empty &&
51+
(
52+
cd empty &&
53+
git symbolic-ref HEAD >expect &&
54+
test_must_fail git checkout &&
55+
git symbolic-ref HEAD >actual &&
56+
test_cmp expect actual
57+
)
58+
'
59+
4960
test_done

0 commit comments

Comments
 (0)