Skip to content

Commit

Permalink
Merge branch 'jc/maint-do-not-switch-to-non-commit'
Browse files Browse the repository at this point in the history
* jc/maint-do-not-switch-to-non-commit:
  git checkout: do not allow switching to a tree-ish that is not a commit
  • Loading branch information
Junio C Hamano committed Jan 3, 2009
2 parents caf8b2f + 3442ea4 commit 8ea6ae9
Show file tree
Hide file tree
Showing 2 changed files with 5 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 @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions t/t2011-checkout-invalid-head.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down

0 comments on commit 8ea6ae9

Please sign in to comment.