{"thread":{"id":"8757","subject":"[PATCH] git-clone: fetch possibly detached HEAD over dumb http","startedAt":"2007-06-28T10:52:08Z","lastAt":"2007-07-01T16:40:16Z","messageCount":9,"participants":["Sven Verdoolaege","Junio C Hamano","Alex Riesen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"45966","messageId":"20070628105208.GA11105@liacs.nl","threadId":"8757","inReplyTo":null,"subject":"[PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Sven Verdoolaege","fromEmail":"skimo@liacs.nl","sentAt":"2007-06-28T10:52:08Z","receivedAt":"2007-06-28T10:52:08Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"git-clone supports cloning from a repo with detached HEAD,\nbut if this HEAD is not behind any branch tip then it\nwould not have been fetched over dumb http, resulting in a\n\n\tfatal: Not a valid object name HEAD\n\nSince 928c210a, this would also happen on a http repo\nwith a HEAD that is a symbolic link where someone has\nforgotton to run update-server-info.\n\nSigned-off-by: Sven Verdoolaege <skimo@liacs.nl>\n---\n git-clone.sh |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex bd44ce1..cdbbc20 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -70,7 +70,8 @@ Perhaps git-update-server-info needs to be run there?\"\n \t\tgit-http-fetch $v -a -w \"$tname\" \"$sha1\" \"$1\" || exit 1\n \tdone <\"$clone_tmp/refs\"\n \trm -fr \"$clone_tmp\"\n-\thttp_fetch \"$1/HEAD\" \"$GIT_DIR/REMOTE_HEAD\" ||\n+\thttp_fetch \"$1/HEAD\" \"$GIT_DIR/REMOTE_HEAD\" &&\n+\tgit-http-fetch $v -a $(cat \"$GIT_DIR/REMOTE_HEAD\") \"$1\" ||\n \trm -f \"$GIT_DIR/REMOTE_HEAD\"\n }\n \n-- \n1.5.2.2.585.g9cc0-dirty\n"},{"id":"46012","messageId":"7vsl8bmxv9.fsf@assigned-by-dhcp.pobox.com","threadId":"8757","inReplyTo":"20070628105208.GA11105@liacs.nl","subject":"Re: [PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-29T00:02:18Z","receivedAt":"2007-06-29T00:02:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sven Verdoolaege <skimo@liacs.nl> writes:\n\n> git-clone supports cloning from a repo with detached HEAD,\n> but if this HEAD is not behind any branch tip then it\n> would not have been fetched over dumb http, resulting in a\n>\n> \tfatal: Not a valid object name HEAD\n>\n> Since 928c210a, this would also happen on a http repo\n> with a HEAD that is a symbolic link where someone has\n> forgotton to run update-server-info.\n>\n> Signed-off-by: Sven Verdoolaege <skimo@liacs.nl>\n\nOk.  But I think the change regresses when the remote side is\nactually on a particular branch, and is using symref to\nrepresent $GIT_DIR/HEAD.\n\n>  git-clone.sh |    3 ++-\n>  1 files changed, 2 insertions(+), 1 deletions(-)\n>\n> diff --git a/git-clone.sh b/git-clone.sh\n> index bd44ce1..cdbbc20 100755\n> --- a/git-clone.sh\n> +++ b/git-clone.sh\n> @@ -70,7 +70,8 @@ Perhaps git-update-server-info needs to be run there?\"\n>  \t\tgit-http-fetch $v -a -w \"$tname\" \"$sha1\" \"$1\" || exit 1\n>  \tdone <\"$clone_tmp/refs\"\n>  \trm -fr \"$clone_tmp\"\n> -\thttp_fetch \"$1/HEAD\" \"$GIT_DIR/REMOTE_HEAD\" ||\n> +\thttp_fetch \"$1/HEAD\" \"$GIT_DIR/REMOTE_HEAD\" &&\n> +\tgit-http-fetch $v -a $(cat \"$GIT_DIR/REMOTE_HEAD\") \"$1\" ||\n>  \trm -f \"$GIT_DIR/REMOTE_HEAD\"\n>  }\n\nAt this point, \"$GIT_DIR/REMOTE_HEAD\" is a copy of HEAD obtained\nfrom the remote site via curl.  It can contain:\n\n (1) raw SHA-1 of the tip commit, if the HEAD is detached, or\n     the repository uses a symlink to represent HEAD, or\n\n (2) \"ref: refs/heads/$currentbranch\".\n\nYou would want to do this extra fetch only in case (1).\nI think the additional fetch would fail in case (2), and result\nin removal of $GIT_DIR/REMOTE_HEAD.\n\nHmm?\n"},{"id":"46033","messageId":"20070629081100.GA7969MdfPADPa@greensroom.kotnet.org","threadId":"8757","inReplyTo":"7vsl8bmxv9.fsf@assigned-by-dhcp.pobox.com","subject":"Re: [PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2007-06-29T08:11:00Z","receivedAt":"2007-06-29T08:11:00Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"On Thu, Jun 28, 2007 at 05:02:18PM -0700, Junio C Hamano wrote:\n> You would want to do this extra fetch only in case (1).\n> I think the additional fetch would fail in case (2), and result\n> in removal of $GIT_DIR/REMOTE_HEAD.\n\nYou're right.  It looks like I only tested it on symbolic link HEADs.\nSorry about that.  Will send a corrected patch later.\n\nskimo\n"},{"id":"46035","messageId":"20070629083108.GA14747@liacs.nl","threadId":"8757","inReplyTo":"7vsl8bmxv9.fsf@assigned-by-dhcp.pobox.com","subject":"[PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Sven Verdoolaege","fromEmail":"skimo@liacs.nl","sentAt":"2007-06-29T08:31:08Z","receivedAt":"2007-06-29T08:31:08Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"git-clone supports cloning from a repo with detached HEAD,\nbut if this HEAD is not behind any branch tip then it\nwould not have been fetched over dumb http, resulting in a\n\n\tfatal: Not a valid object name HEAD\n\nSince 928c210a, this would also happen on a http repo\nwith a HEAD that is a symbolic link where someone has\nforgotton to run update-server-info.\n\nSigned-off-by: Sven Verdoolaege <skimo@liacs.nl>\n---\nOn Thu, Jun 28, 2007 at 05:02:18PM -0700, Junio C Hamano wrote:\n> Ok.  But I think the change regresses when the remote side is\n> actually on a particular branch, and is using symref to\n> represent $GIT_DIR/HEAD.\n\nUpdated patch tested on both symbolic links and symrefs.\n\nskimo\n\n git-clone.sh |   11 +++++++++++\n 1 files changed, 11 insertions(+), 0 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex bd44ce1..4cbf60f 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -72,6 +72,17 @@ Perhaps git-update-server-info needs to be run there?\"\n \trm -fr \"$clone_tmp\"\n \thttp_fetch \"$1/HEAD\" \"$GIT_DIR/REMOTE_HEAD\" ||\n \trm -f \"$GIT_DIR/REMOTE_HEAD\"\n+\tif test -f \"$GIT_DIR/REMOTE_HEAD\"; then\n+\t\thead_sha1=`cat \"$GIT_DIR/REMOTE_HEAD\"`\n+\t\tcase \"$head_sha1\" in\n+\t\t'ref: refs/'*)\n+\t\t\t;;\n+\t\t*)\n+\t\t\tgit-http-fetch $v -a \"$head_sha1\" \"$1\" ||\n+\t\t\trm -f \"$GIT_DIR/REMOTE_HEAD\"\n+\t\t\t;;\n+\t\tesac\n+\tfi\n }\n \n quiet=\n-- \n1.5.2.2.585.g9cc0-dirty\n"},{"id":"46087","messageId":"20070630133310.GB2866@steel.home","threadId":"8757","inReplyTo":"20070629083108.GA14747@liacs.nl","subject":"Re: [PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-06-30T13:33:10Z","receivedAt":"2007-06-30T13:33:10Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Sven Verdoolaege, Fri, Jun 29, 2007 10:31:08 +0200:\n> +\t\thead_sha1=`cat \"$GIT_DIR/REMOTE_HEAD\"`\n> +\t\tcase \"$head_sha1\" in\n> +\t\t'ref: refs/'*)\n> +\t\t\t;;\n\nAnd what do you do if the HEAD is a reflink on something not in refs/?\nLike \"ref: tmp\"? Yes, it is unlikely, but is not forbidden.\n\nHow about \"[0-9a-f]*)\" instead:\n\n               case \"$head_sha1\" in\n               [0-9a-f]*)\n                       git-http-fetch $v -a \"$head_sha1\" \"$1\" ||\n                       rm -f \"$GIT_DIR/REMOTE_HEAD\"\n                       ;;\n               esac\n"},{"id":"46088","messageId":"20070630134542.GF7969MdfPADPa@greensroom.kotnet.org","threadId":"8757","inReplyTo":"20070630133310.GB2866@steel.home","subject":"Re: [PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2007-06-30T13:45:44Z","receivedAt":"2007-06-30T13:45:44Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"On Sat, Jun 30, 2007 at 03:33:10PM +0200, Alex Riesen wrote:\n> Sven Verdoolaege, Fri, Jun 29, 2007 10:31:08 +0200:\n> > +\t\thead_sha1=`cat \"$GIT_DIR/REMOTE_HEAD\"`\n> > +\t\tcase \"$head_sha1\" in\n> > +\t\t'ref: refs/'*)\n> > +\t\t\t;;\n> \n> And what do you do if the HEAD is a reflink on something not in refs/?\n> Like \"ref: tmp\"? Yes, it is unlikely, but is not forbidden.\n\nIt may not be forbidden, but I don't think it would\nwork with current git-clone either.\n\nskimo\n"},{"id":"46131","messageId":"20070630222336.GA2703@steel.home","threadId":"8757","inReplyTo":"20070630134542.GF7969MdfPADPa@greensroom.kotnet.org","subject":"Re: [PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-06-30T22:23:36Z","receivedAt":"2007-06-30T22:23:36Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Sven Verdoolaege, Sat, Jun 30, 2007 15:45:44 +0200:\n> On Sat, Jun 30, 2007 at 03:33:10PM +0200, Alex Riesen wrote:\n> > Sven Verdoolaege, Fri, Jun 29, 2007 10:31:08 +0200:\n> > > +\t\thead_sha1=`cat \"$GIT_DIR/REMOTE_HEAD\"`\n> > > +\t\tcase \"$head_sha1\" in\n> > > +\t\t'ref: refs/'*)\n> > > +\t\t\t;;\n> > \n> > And what do you do if the HEAD is a reflink on something not in refs/?\n> > Like \"ref: tmp\"? Yes, it is unlikely, but is not forbidden.\n> \n> It may not be forbidden, but I don't think it would\n> work with current git-clone either.\n> \n\nEvery command which needs a proper .git will not work, so I take this\nback completely.\n\nThe check for .git validity includes checking if HEAD contains\nsomething sane, and this check is very simple: the HEAD is read\n(readlink(2) or plain read(2)) and tested if it contains a\nreference starting with \"refs/\", which maybe inconsistent with\nresolve_gitlink_ref, but probably ok.\n"},{"id":"46138","messageId":"7vy7i0amnn.fsf@assigned-by-dhcp.cox.net","threadId":"8757","inReplyTo":"20070630222336.GA2703@steel.home","subject":"Re: [PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-01T02:22:04Z","receivedAt":"2007-07-01T02:22:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> writes:\n\n> The check for .git validity includes checking if HEAD contains\n> something sane, and this check is very simple: the HEAD is read\n> (readlink(2) or plain read(2)) and tested if it contains a\n> reference starting with \"refs/\", which maybe inconsistent with\n> resolve_gitlink_ref, but probably ok.\n\nAh, I was not paying close attention to resolve_gitlink_ref();\nif it does not require HEAD to point at refs/ I would say it is\na bug.\n\nCome to think of it, I would further say that we probably should\ntighten it up a bit: HEAD must be either a valid commit object\nname (i.e. detached) or a ref that point at somewhere under\nrefs/heads hierarchy, not just anywhere in refs/.\n"},{"id":"46180","messageId":"20070701164016.GA3661@steel.home","threadId":"8757","inReplyTo":"7vy7i0amnn.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-clone: fetch possibly detached HEAD over dumb http","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-07-01T16:40:16Z","receivedAt":"2007-07-01T16:40:16Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Junio C Hamano, Sun, Jul 01, 2007 04:22:04 +0200:\n> Alex Riesen <raa.lkml@gmail.com> writes:\n> \n> > The check for .git validity includes checking if HEAD contains\n> > something sane, and this check is very simple: the HEAD is read\n> > (readlink(2) or plain read(2)) and tested if it contains a\n> > reference starting with \"refs/\", which maybe inconsistent with\n> > resolve_gitlink_ref, but probably ok.\n> \n> Ah, I was not paying close attention to resolve_gitlink_ref();\n> if it does not require HEAD to point at refs/ I would say it is\n> a bug.\n\nyes, thats why I think its ok.\n\n> Come to think of it, I would further say that we probably should\n> tighten it up a bit: HEAD must be either a valid commit object\n> name (i.e. detached)\n\nThat (HEAD must point to a _valid_ commit) will make accidentally\ncorrupted repositories harder to fix. The tool which require a valid\nrepository (cat-file, update-ref, read-tree) are the same tools which\nyou need to fix small problems which can happen, like the commit\npointed by HEAD is accidentally pruned from parent repo.\n"}]}