aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-05-11 11:34:16 -0700
committerJunio C Hamano <gitster@pobox.com>2012-05-11 11:34:17 -0700
commita735b79c6357ad5ccc202c29d31b561ad14c75b0 (patch)
tree450f62d4aa0bf703d2ab564c82c0325650898dcf
parentd318a3997a76155795f28ffefb52158c0c4133ab (diff)
parent8338f771fe9720766dfcb25b6dca58832e24a0fd (diff)
downloadgit-a735b79c6357ad5ccc202c29d31b561ad14c75b0.tar.gz
git-a735b79c6357ad5ccc202c29d31b561ad14c75b0.tar.xz
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
-rw-r--r--builtin/checkout.c2
-rwxr-xr-xt/t2015-checkout-unborn.sh11
2 files changed, 12 insertions, 1 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index c93efe4d9..3ddda34f7 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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;
diff --git a/t/t2015-checkout-unborn.sh b/t/t2015-checkout-unborn.sh
index 6352b74e2..37bdcedcc 100755
--- a/t/t2015-checkout-unborn.sh
+++ b/t/t2015-checkout-unborn.sh
@@ -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