Skip to content

Commit

Permalink
Merge branch 'ef/checkout-empty'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Junio C Hamano committed May 11, 2012
2 parents d318a39 + 8338f77 commit a735b79
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
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;

Expand Down
11 changes: 11 additions & 0 deletions t/t2015-checkout-unborn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ test_expect_success 'checking out another branch from unborn state' '
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

0 comments on commit a735b79

Please sign in to comment.