Merge branch 'ef/checkout-empty' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 14 May 2012 18:42:49 +0000 (11:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 May 2012 18:42:50 +0000 (11:42 -0700)
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

builtin/checkout.c
t/t2015-checkout-unborn.sh
index 160f678b8cae006953ce7b4f9bdd424e53ce47f7..c3647934c786b0da0caf3a9392428c95dcd60e1b 100644 (file)
@@ -1091,7 +1091,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;
 
index 6352b74e2e54e5e08941d8d5d90ac30b202b56c1..37bdcedcc952083ba336cb9eaca5c67424d2cbb6 100755 (executable)
@@ -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