summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 27c03aa)
raw | patch | inline | side by side (parent: 27c03aa)
author | Junio C Hamano <gitster@pobox.com> | |
Sat, 3 Jan 2009 12:07:32 +0000 (04:07 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sat, 3 Jan 2009 21:34:19 +0000 (13:34 -0800) |
"git checkout -b newbranch $commit^{tree}" mistakenly created a new branch
rooted at the current HEAD, because in that case, the two structure fields
used to see if the command was invoked without any argument (hence it
needs to default to checking out the HEAD) were populated incorrectly.
Upon seeing a command line argument that we took as a rev, we should store
that string in new.name, even if that does not name a commit. This will
correctly trigger the existing safety logic.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Daniel Barkalow <barkalow@iabervon.org>
rooted at the current HEAD, because in that case, the two structure fields
used to see if the command was invoked without any argument (hence it
needs to default to checking out the HEAD) were populated incorrectly.
Upon seeing a command line argument that we took as a rev, we should store
that string in new.name, even if that does not name a commit. This will
correctly trigger the existing safety logic.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Daniel Barkalow <barkalow@iabervon.org>
builtin-checkout.c | patch | blob | history | |
t/t2011-checkout-invalid-head.sh | patch | blob | history |
diff --git a/builtin-checkout.c b/builtin-checkout.c
index c107fd643a452edb016f7ad867d4b2a555d9abaf..544aa5add14b43f9d44caf3fecf874fd3498dd6e 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
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)
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 --