Code

Merge branch 'jc/maint-do-not-switch-to-non-commit'
authorJunio C Hamano <gitster@pobox.com>
Sat, 3 Jan 2009 21:57:30 +0000 (13:57 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 3 Jan 2009 21:57:30 +0000 (13:57 -0800)
* jc/maint-do-not-switch-to-non-commit:
  git checkout: do not allow switching to a tree-ish that is not a commit

builtin-checkout.c
t/t2011-checkout-invalid-head.sh

index c2c05613b67d7cc8bd3500bdbca4fc3533afaeee..b5dd9c07b42e0130384259715730f52bc8c4e6c3 100644 (file)
@@ -681,8 +681,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                argv++;
                argc--;
 
+               new.name = arg;
                if ((new.commit = lookup_commit_reference_gently(rev, 1))) {
-                       new.name = arg;
                        setup_branch_path(&new);
                        if (resolve_ref(new.path, rev, 1, NULL))
                                new.commit = lookup_commit_reference(rev);
index 764bb0a6bc3de1f3313fb16c384bbd37c82ae5da..15ebdc26ebaaf7881b1f51eb788c2eb2922b6d4f 100755 (executable)
@@ -10,6 +10,10 @@ test_expect_success 'setup' '
        git commit -m initial
 '
 
+test_expect_success 'checkout should not start branch from a tree' '
+       test_must_fail git checkout -b newbranch master^{tree}
+'
+
 test_expect_success 'checkout master from invalid HEAD' '
        echo 0000000000000000000000000000000000000000 >.git/HEAD &&
        git checkout master --