{"thread":{"id":"16961","subject":"git checkout does not warn about tags without corresponding commits","startedAt":"2009-01-02T12:25:57Z","lastAt":"2009-01-03T19:31:24Z","messageCount":8,"participants":["Henrik Austad","Miklos Vajna","Junio C Hamano","Daniel Barkalow"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"99162","messageId":"200901021325.58049.henrik@austad.us","threadId":"16961","inReplyTo":null,"subject":"git checkout does not warn about tags without corresponding commits","fromName":"Henrik Austad","fromEmail":"henrik@austad.us","sentAt":"2009-01-02T12:25:57Z","receivedAt":"2009-01-02T12:25:57Z","isPatch":false,"sender":{"key":"henrik@austad.us","avatar":"https://gravatar.com/avatar/c3f6bb245c70f4ee4c8af7c4b067694462f1a35c006daa806d4dd09f914eeed6?d=mp&s=160"},"body":"Hi!\n\nI recently tried to do a checkout of (what I thought was the first) inux \nkernel in the linux git repo.\n\n\ngit checkout -b 2.6.11 v2.6.11\n\nThis tag exists in the linux-tree (direct clone from Linus' tree), along with \nv2.6.11-tree\n\nHowever, when I inspect the log, I see that I am still stuck in master. So, I \ndid a git tag -v v2.6.11 and got the following:\n\nobject c39ae07f393806ccf406ef966e9a15afc43cc36a\ntype tree\ntag v2.6.11-tree\n\nThis is the 2.6.11 tree object.\n\nNOTE! There's no commit for this, since it happened before I started with git.\nEventually we'll import some sort of history, and that should tie this tree\nobject up to a real commit. In the meantime, this acts as an anchor point for\ndoing diffs etc under git.\ngpg: Signature made Thu 05 May 2005 01:50:54 AM CEST using DSA key ID 76E21CBB\ngpg: Good signature from \"Linus Torvalds (tag signing key) \n<torvalds@osdl.org>\"\ngpg: WARNING: This key is not certified with a trusted signature!\ngpg:          There is no indication that the signature belongs to the owner.\nPrimary key fingerprint: FF6D 4EAC 37AC C1B9 53AE  C7E8 1776 2C46 76E2 1CBB\n\n\nI can see that there's no commit for this, but, when there's a tag. I thought \nthat a tag was just a commit-sha1 with a name attached, along with some tag \ninfo and a signature. Can you really create a tag without a commit?\n\nShouldn't git checkout fail in some way, letting me know that the checkout did \nnot check out what I thought it did? (I got aware of the bug when I found \nCFS-related code in something I thought was 2.6.11.. :-)\n\n\n-- \n -> henrik\n"},{"id":"99168","messageId":"20090102150437.GN21154@genesis.frugalware.org","threadId":"16961","inReplyTo":"200901021325.58049.henrik@austad.us","subject":"Re: git checkout does not warn about tags without corresponding commits","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2009-01-02T15:04:37Z","receivedAt":"2009-01-02T15:04:37Z","isPatch":false,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Fri, Jan 02, 2009 at 01:25:57PM +0100, Henrik Austad <henrik@austad.us> wrote:\n> I can see that there's no commit for this, but, when there's a tag. I thought \n> that a tag was just a commit-sha1 with a name attached, along with some tag \n> info and a signature. Can you really create a tag without a commit?\n\nSure, you can tag any object type (blob, tree, commit or tag), but\nusually only commits are tagged.\n\nSee for example the 'junio-gpg-pub' tag in git.git which tags a blob.\n"},{"id":"99205","messageId":"7v8wptcrhp.fsf@gitster.siamese.dyndns.org","threadId":"16961","inReplyTo":"200901021325.58049.henrik@austad.us","subject":"Re: git checkout does not warn about tags without corresponding commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-02T21:44:50Z","receivedAt":"2009-01-02T21:44:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Henrik Austad <henrik@austad.us> writes:\n\n> I recently tried to do a checkout of (what I thought was the first) inux \n> kernel in the linux git repo.\n>\n> git checkout -b 2.6.11 v2.6.11\n\nThis should have barfed, and indeed I think it is a regression around\nv1.5.5.  v1.5.4 and older git definitely fails to check out a tree object\nlike that.\n"},{"id":"99246","messageId":"200901031200.01883.henrik@austad.us","threadId":"16961","inReplyTo":"7v8wptcrhp.fsf@gitster.siamese.dyndns.org","subject":"Re: git checkout does not warn about tags without corresponding commits","fromName":"Henrik Austad","fromEmail":"henrik@austad.us","sentAt":"2009-01-03T11:00:01Z","receivedAt":"2009-01-03T11:00:01Z","isPatch":false,"sender":{"key":"henrik@austad.us","avatar":"https://gravatar.com/avatar/c3f6bb245c70f4ee4c8af7c4b067694462f1a35c006daa806d4dd09f914eeed6?d=mp&s=160"},"body":"On Friday 02 January 2009 22:44:50 Junio C Hamano wrote:\n> Henrik Austad <henrik@austad.us> writes:\n> > I recently tried to do a checkout of (what I thought was the first) inux\n> > kernel in the linux git repo.\n> >\n> > git checkout -b 2.6.11 v2.6.11\n>\n> This should have barfed, and indeed I think it is a regression around\n> v1.5.5.  v1.5.4 and older git definitely fails to check out a tree object\n> like that.\n\nYou're right, I bisected it down to commit \n782c2d65c24066a5d83453efb52763bc34c10f81\n\nIt introduces quite a large change, adding checkout-builtin.c, which coud be \nthe cause I guess.\n\nAs of how to fix this (if a fix is desired) I have not yet any clue what so \never :-)\n\nI attached the bisect result (sorry if attachements are frowned upon, but my \nemail client tends to mutilate text-contents like that).\n\n-- \n -> henrik\n\n\n782c2d65c24066a5d83453efb52763bc34c10f81 is first bad commit\ncommit 782c2d65c24066a5d83453efb52763bc34c10f81\nAuthor: Daniel Barkalow <barkalow@iabervon.org>\nDate:   Thu Feb 7 11:40:23 2008 -0500\n\n    Build in checkout\n\n    The only differences in behavior should be:\n\n     - git checkout -m with non-trivial merging won't print out\n       merge-recursive messages (see the change in t7201-co.sh)\n\n     - git checkout -- paths... will give a sensible error message if\n       HEAD is invalid as a commit.\n\n     - some intermediate states which were written to disk in the shell\n       version (in particular, index states) are only kept in memory in\n       this version, and therefore these can no longer be revealed by\n       later write operations becoming impossible.\n\n     - when we change branches, we discard MERGE_MSG, SQUASH_MSG, and\n       rr-cache/MERGE_RR, like reset always has.\n\n    I'm not 100% sure I got the merge recursive setup exactly right; the\n    base for a non-trivial merge in the shell code doesn't seem\n    theoretically justified to me, but I tried to match it anyway, and the\n    tests all pass this way.\n\n    Other than these items, the results should be identical to the shell\n    version, so far as I can tell.\n\n    [jc: squashed lock-file fix from Dscho in]\n\n    Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>\n    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n    Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\n:100644 100644 5cfadfd307d588a427e200576ba97a5227653a13 90c0dd8c43cd66008d29492bdfb6b21a17855a00 M      Makefile\n:000000 100644 0000000000000000000000000000000000000000 59a0ef4ec9770af6d031abe959adc587c9538a89 A      builtin-checkout.c\n:100644 100644 428160d0e48b2acf1ac54d6d73910fd93151ca22 25d91bbfb21ea3c1ea067b10f7ea033d3563936a M      builtin.h\n:040000 040000 098e84f3f9fc152debb0f92eb849127f460391d7 0860a331e5a98a88a143d32f371385e78a0121d8 M      contrib\n:100755 000000 5621c69d86062c7c75c0b8c2749d34efc78cafb4 0000000000000000000000000000000000000000 D      git-checkout.sh\n:100644 100644 114ea75eef55e2960ff111014a505c3eb678caae fc156863b0bbd7d264864c49c2529e47709abf4d M      git.c\n:040000 040000 49b19f06ce0395f99f5b9729a1e51b5fa7fd1875 4165e146453fa357ef5e76a9ad48e683301ae669 M      t\n\n"},{"id":"99247","messageId":"7vr63k8vvf.fsf@gitster.siamese.dyndns.org","threadId":"16961","inReplyTo":"200901031200.01883.henrik@austad.us","subject":"Re: git checkout does not warn about tags without corresponding commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-03T11:36:04Z","receivedAt":"2009-01-03T11:36:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Henrik Austad <henrik@austad.us> writes:\n\n> On Friday 02 January 2009 22:44:50 Junio C Hamano wrote:\n>> Henrik Austad <henrik@austad.us> writes:\n>> > I recently tried to do a checkout of (what I thought was the first) inux\n>> > kernel in the linux git repo.\n>> >\n>> > git checkout -b 2.6.11 v2.6.11\n>>\n>> This should have barfed, and indeed I think it is a regression around\n>> v1.5.5.  v1.5.4 and older git definitely fails to check out a tree object\n>> like that.\n>\n> You're right, I bisected it down to commit \n> 782c2d65c24066a5d83453efb52763bc34c10f81\n\nI am not surprised.\n\nThat one discarded an implementation of \"git checkout\" in Bourne shell,\nwith a complete reimplementation in C.\n\nI haven't looked at the code very closely, but I think this should fix\nit.  Thorough reviewing (not just running the test suite) is much\nappreciated.\n\n-- >8 --\nSubject: git-checkout: do not allow switching to a tree-ish\n\n\"git checkout -b newbranch $commit^{tree}\" mistakenly created a new branch\nrooted at the current HEAD, because in that case, the two structure fields\nused to see if the command was invoked without any argument (hence it\nneeds to default to checking out the HEAD), were populated incorrectly.\n\nUpon seeing a command line argument that we took as a rev, we should store\nthat string in new.name, even if that does not name a commit.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-checkout.c               |    2 +-\n t/t2011-checkout-invalid-head.sh |    4 ++++\n 2 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git c/builtin-checkout.c w/builtin-checkout.c\nindex c2c0561..b5dd9c0 100644\n--- c/builtin-checkout.c\n+++ w/builtin-checkout.c\n@@ -681,8 +681,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t\targv++;\n \t\targc--;\n \n+\t\tnew.name = arg;\n \t\tif ((new.commit = lookup_commit_reference_gently(rev, 1))) {\n-\t\t\tnew.name = arg;\n \t\t\tsetup_branch_path(&new);\n \t\t\tif (resolve_ref(new.path, rev, 1, NULL))\n \t\t\t\tnew.commit = lookup_commit_reference(rev);\ndiff --git c/t/t2011-checkout-invalid-head.sh w/t/t2011-checkout-invalid-head.sh\nindex 764bb0a..798790d 100755\n--- c/t/t2011-checkout-invalid-head.sh\n+++ w/t/t2011-checkout-invalid-head.sh\n@@ -15,4 +15,8 @@ test_expect_success 'checkout master from invalid HEAD' '\n \tgit checkout master --\n '\n \n+test_expect_success 'checkout should not start branch from a tree' '\n+\ttest_must_fail git checkout -b newbranch master^{tree}\n+'\n+\n test_done\n"},{"id":"99248","messageId":"7vbpuo7ghz.fsf@gitster.siamese.dyndns.org","threadId":"16961","inReplyTo":"7vr63k8vvf.fsf@gitster.siamese.dyndns.org","subject":"Re: git checkout does not warn about tags without corresponding commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-03T11:53:28Z","receivedAt":"2009-01-03T11:53:28Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> I haven't looked at the code very closely, but I think this should fix\n> it.  Thorough reviewing (not just running the test suite) is much\n> appreciated.\n\nJust for fun, this will apply to 782c2d6 (Build in checkout, 2008-02-07)\nand seems to fix the issue ;-)\n\nNo, I am not going to issue a maintenance release for 1.5.5 just to\ninclude this fix, even though I could.  I do not think this is a grave\nenough regression to warrant a backport beyond 1.6.0 series.\n\n builtin-checkout.c |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\ndiff --git i/builtin-checkout.c w/builtin-checkout.c\nindex 59a0ef4..1d0de68 100644\n--- i/builtin-checkout.c\n+++ w/builtin-checkout.c\n@@ -435,6 +435,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t\t\targv++;\n \t\t\targc--;\n \t\t} else if ((source_tree = parse_tree_indirect(rev))) {\n+\t\t\tnew.name = arg;\n \t\t\targv++;\n \t\t\targc--;\n \t\t}\n"},{"id":"99251","messageId":"200901031337.00166.henrik@austad.us","threadId":"16961","inReplyTo":"7vr63k8vvf.fsf@gitster.siamese.dyndns.org","subject":"Re: git checkout does not warn about tags without corresponding commits","fromName":"Henrik Austad","fromEmail":"henrik@austad.us","sentAt":"2009-01-03T12:37:00Z","receivedAt":"2009-01-03T12:37:00Z","isPatch":false,"sender":{"key":"henrik@austad.us","avatar":"https://gravatar.com/avatar/c3f6bb245c70f4ee4c8af7c4b067694462f1a35c006daa806d4dd09f914eeed6?d=mp&s=160"},"body":"On Saturday 03 January 2009 12:36:04 Junio C Hamano wrote:\n> Henrik Austad <henrik@austad.us> writes:\n> > On Friday 02 January 2009 22:44:50 Junio C Hamano wrote:\n> >> Henrik Austad <henrik@austad.us> writes:\n> >> > I recently tried to do a checkout of (what I thought was the first)\n> >> > inux kernel in the linux git repo.\n> >> >\n> >> > git checkout -b 2.6.11 v2.6.11\n> >>\n> >> This should have barfed, and indeed I think it is a regression around\n> >> v1.5.5.  v1.5.4 and older git definitely fails to check out a tree\n> >> object like that.\n> >\n> > You're right, I bisected it down to commit\n> > 782c2d65c24066a5d83453efb52763bc34c10f81\n>\n> I am not surprised.\n>\n> That one discarded an implementation of \"git checkout\" in Bourne shell,\n> with a complete reimplementation in C.\n>\n> I haven't looked at the code very closely, but I think this should fix\n> it.  Thorough reviewing (not just running the test suite) is much\n> appreciated.\n>\n> -- >8 --\n> Subject: git-checkout: do not allow switching to a tree-ish\n>\n> \"git checkout -b newbranch $commit^{tree}\" mistakenly created a new branch\n> rooted at the current HEAD, because in that case, the two structure fields\n> used to see if the command was invoked without any argument (hence it\n> needs to default to checking out the HEAD), were populated incorrectly.\n>\n> Upon seeing a command line argument that we took as a rev, we should store\n> that string in new.name, even if that does not name a commit.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  builtin-checkout.c               |    2 +-\n>  t/t2011-checkout-invalid-head.sh |    4 ++++\n>  2 files changed, 5 insertions(+), 1 deletions(-)\n>\n> diff --git c/builtin-checkout.c w/builtin-checkout.c\n> index c2c0561..b5dd9c0 100644\n> --- c/builtin-checkout.c\n> +++ w/builtin-checkout.c\n> @@ -681,8 +681,8 @@ int cmd_checkout(int argc, const char **argv, const\n> char *prefix) argv++;\n>  \t\targc--;\n>\n> +\t\tnew.name = arg;\n>  \t\tif ((new.commit = lookup_commit_reference_gently(rev, 1))) {\n> -\t\t\tnew.name = arg;\n>  \t\t\tsetup_branch_path(&new);\n>  \t\t\tif (resolve_ref(new.path, rev, 1, NULL))\n>  \t\t\t\tnew.commit = lookup_commit_reference(rev);\n\n\nthis fixed my problem when i hacked this into master (git apply failed on the \npatch, so I did a manual patch. Moving that line did the trick\n\nAcked-by/Signed-off-by Henrik Austad <henrik@austad.us>\n\n\n> diff --git c/t/t2011-checkout-invalid-head.sh\n> w/t/t2011-checkout-invalid-head.sh index 764bb0a..798790d 100755\n> --- c/t/t2011-checkout-invalid-head.sh\n> +++ w/t/t2011-checkout-invalid-head.sh\n> @@ -15,4 +15,8 @@ test_expect_success 'checkout master from invalid HEAD' '\n>  \tgit checkout master --\n>  '\n>\n> +test_expect_success 'checkout should not start branch from a tree' '\n> +\ttest_must_fail git checkout -b newbranch master^{tree}\n> +'\n> +\n>  test_done\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n\n\n\n-- \n -> henrik\n"},{"id":"99264","messageId":"alpine.LNX.1.00.0901031410130.19665@iabervon.org","threadId":"16961","inReplyTo":"7vr63k8vvf.fsf@gitster.siamese.dyndns.org","subject":"Re: git checkout does not warn about tags without corresponding commits","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-01-03T19:31:24Z","receivedAt":"2009-01-03T19:31:24Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Sat, 3 Jan 2009, Junio C Hamano wrote:\n\n> Henrik Austad <henrik@austad.us> writes:\n> \n> > On Friday 02 January 2009 22:44:50 Junio C Hamano wrote:\n> >> Henrik Austad <henrik@austad.us> writes:\n> >> > I recently tried to do a checkout of (what I thought was the first) inux\n> >> > kernel in the linux git repo.\n> >> >\n> >> > git checkout -b 2.6.11 v2.6.11\n> >>\n> >> This should have barfed, and indeed I think it is a regression around\n> >> v1.5.5.  v1.5.4 and older git definitely fails to check out a tree object\n> >> like that.\n> >\n> > You're right, I bisected it down to commit \n> > 782c2d65c24066a5d83453efb52763bc34c10f81\n> \n> I am not surprised.\n> \n> That one discarded an implementation of \"git checkout\" in Bourne shell,\n> with a complete reimplementation in C.\n> \n> I haven't looked at the code very closely, but I think this should fix\n> it.  Thorough reviewing (not just running the test suite) is much\n> appreciated.\n\nThat looks right to me.\n\nAcked-by: Daniel Barkalow <barkalow@iabervon.org>\n\n\t-Daniel\n*This .sig left intentionally blank*\n"}]}