{"thread":{"id":"21232","subject":"[PATCH] clone: Supply the right commit hash to post-checkout when -b is used","startedAt":"2009-10-13T22:11:09Z","lastAt":"2009-10-14T09:13:50Z","messageCount":3,"participants":["Björn Steinbrink","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"124908","messageId":"20091013221109.GA30972@atjola.homenet","threadId":"21232","inReplyTo":null,"subject":"[PATCH] clone: Supply the right commit hash to post-checkout when -b is used","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-10-13T22:11:09Z","receivedAt":"2009-10-13T22:11:09Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"When we use -b <branch>, we may checkout something else than what the\nremote's HEAD references, but we still used remote_head to supply the\nnew ref value to the post-checkout hook, which is wrong.\n\nSo instead of using remote_head to find the value to be passed to the\npost-checkout hook, we have to use our_head_points_at, which is always\ncorrectly setup, even if -b is not used.\n\nThis also fixes a segfault when \"clone -b <branch>\" is used with a\nremote repo that doesn't have a valid HEAD, as in such a case\nremote_head is NULL, but we still tried to access it.\n\nReported-by: Devin Cofer <ranguvar@archlinux.us>\nSigned-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n---\n builtin-clone.c |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-clone.c b/builtin-clone.c\nindex 4992c25..5762a6f 100644\n--- a/builtin-clone.c\n+++ b/builtin-clone.c\n@@ -641,7 +641,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\t\tdie(\"unable to write new index file\");\n \n \t\terr |= run_hook(NULL, \"post-checkout\", sha1_to_hex(null_sha1),\n-\t\t\t\tsha1_to_hex(remote_head->old_sha1), \"1\", NULL);\n+\t\t\t\tsha1_to_hex(our_head_points_at->old_sha1), \"1\",\n+\t\t\t\tNULL);\n \n \t\tif (!err && option_recursive)\n \t\t\terr = run_command_v_opt(argv_submodule, RUN_GIT_CMD);\n-- \n1.6.5.7.g9ecb2\n"},{"id":"124915","messageId":"20091014000619.GA20496@coredump.intra.peff.net","threadId":"21232","inReplyTo":"20091013221109.GA30972@atjola.homenet","subject":"Re: [PATCH] clone: Supply the right commit hash to post-checkout when -b is used","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-14T00:06:19Z","receivedAt":"2009-10-14T00:06:19Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Oct 14, 2009 at 12:11:09AM +0200, Björn Steinbrink wrote:\n\n> When we use -b <branch>, we may checkout something else than what the\n> remote's HEAD references, but we still used remote_head to supply the\n> new ref value to the post-checkout hook, which is wrong.\n> \n> So instead of using remote_head to find the value to be passed to the\n> post-checkout hook, we have to use our_head_points_at, which is always\n> correctly setup, even if -b is not used.\n> \n> This also fixes a segfault when \"clone -b <branch>\" is used with a\n> remote repo that doesn't have a valid HEAD, as in such a case\n> remote_head is NULL, but we still tried to access it.\n> \n> Reported-by: Devin Cofer <ranguvar@archlinux.us>\n> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n\nAcked-by: Jeff King <peff@peff.net>\n\nThanks.\n\nWhen splitting remote_head versus our_head, I tried to find every use of\nthe remote head and pick the appropriate variable, but I think I just\nmissed this one. I gave the code another once-over and didn't see any\nother spots that needed fixing.\n\n-Peff\n"},{"id":"124956","messageId":"7vvdiie3sh.fsf@alter.siamese.dyndns.org","threadId":"21232","inReplyTo":"20091014000619.GA20496@coredump.intra.peff.net","subject":"Re: [PATCH] clone: Supply the right commit hash to post-checkout when -b is used","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-14T09:13:50Z","receivedAt":"2009-10-14T09:13:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n>> Reported-by: Devin Cofer <ranguvar@archlinux.us>\n>> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n>\n> Acked-by: Jeff King <peff@peff.net>\n>\n> Thanks.\n\nThanks; will queue on 'maint' for 1.6.5.1.\n"}]}