Commit 8ea6ae99 authored by Junio C Hamano's avatar Junio C Hamano

Merge branch 'jc/maint-do-not-switch-to-non-commit'

* jc/maint-do-not-switch-to-non-commit:
  git checkout: do not allow switching to a tree-ish that is not a commit
parents caf8b2fb 3442ea4a
......@@ -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);
......
......@@ -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 --
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment