{"thread":{"id":"12215","subject":"[PATCH] git-clone.sh: properly configure remote even if remote's head is dangling","startedAt":"2008-02-20T15:10:17Z","lastAt":"2008-02-20T20:17:52Z","messageCount":3,"participants":["Gerrit Pape","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"69373","messageId":"20080220151017.17840.qmail@767a223c93e1c8.315fe32.mid.smarden.org","threadId":"12215","inReplyTo":null,"subject":"[PATCH] git-clone.sh: properly configure remote even if remote's head is dangling","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2008-02-20T15:10:17Z","receivedAt":"2008-02-20T15:10:17Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"When cloning a remote repository which's HEAD refers to a nonexistent\nref, git-clone cloned all existing refs, but failed to write the\nconfiguration for 'remote'.  Now it detects the dangling remote HEAD,\nrefuses to checkout any local branch since HEAD refers to nowhere, but\nproperly writes the configuration for 'remote', so that subsequent\n'git fetch's don't fail.\n\nThe problem was reported by Daniel Jacobowitz through\n http://bugs.debian.org/466581\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\n git-clone.sh           |   18 +++++++++++++-----\n t/t5701-clone-local.sh |    8 ++++++++\n 2 files changed, 21 insertions(+), 5 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex b4e858c..0d686c3 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -409,11 +409,12 @@ else\n \tcd \"$D\" || exit\n fi\n \n-if test -z \"$bare\" && test -f \"$GIT_DIR/REMOTE_HEAD\"\n+if test -z \"$bare\"\n then\n \t# a non-bare repository is always in separate-remote layout\n \tremote_top=\"refs/remotes/$origin\"\n-\thead_sha1=`cat \"$GIT_DIR/REMOTE_HEAD\"`\n+\thead_sha1=\n+\ttest ! -r \"$GIT_DIR/REMOTE_HEAD\" || head_sha1=`cat \"$GIT_DIR/REMOTE_HEAD\"`\n \tcase \"$head_sha1\" in\n \t'ref: refs/'*)\n \t\t# Uh-oh, the remote told us (http transport done against\n@@ -470,9 +471,16 @@ then\n \t\tgit config branch.\"$head_points_at\".merge \"refs/heads/$head_points_at\"\n \t\t;;\n \t'')\n-\t\t# Source had detached HEAD pointing nowhere\n-\t\tgit update-ref --no-deref HEAD \"$head_sha1\" &&\n-\t\trm -f \"refs/remotes/$origin/HEAD\"\n+\t\tif test -z \"$head_sha1\"\n+\t\tthen\n+\t\t\t# Source had nonexistent ref in HEAD\n+\t\t\techo >&2 \"Warning: Remote HEAD refers to nonexistent ref, unable to checkout.\"\n+\t\t\tno_checkout=t\n+\t\telse\n+\t\t\t# Source had detached HEAD pointing nowhere\n+\t\t\tgit update-ref --no-deref HEAD \"$head_sha1\" &&\n+\t\t\trm -f \"refs/remotes/$origin/HEAD\"\n+\t\tfi\n \t\t;;\n \tesac\n \ndiff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh\nindex 822ac8c..59a165a 100755\n--- a/t/t5701-clone-local.sh\n+++ b/t/t5701-clone-local.sh\n@@ -63,4 +63,12 @@ test_expect_success 'Even without -l, local will make a hardlink' '\n \ttest 0 = $copied\n '\n \n+test_expect_success 'local clone of repo with nonexistent ref in HEAD' '\n+\tcd \"$D\" &&\n+\techo \"ref: refs/heads/nonexistent\" > a.git/HEAD &&\n+\tgit clone a d &&\n+\tcd d &&\n+\tgit fetch &&\n+\ttest ! -e .git/refs/remotes/origin/HEAD'\n+\n test_done\n-- \n1.5.4.2\n"},{"id":"69374","messageId":"alpine.LSU.1.00.0802201516570.17164@racer.site","threadId":"12215","inReplyTo":"20080220151017.17840.qmail@767a223c93e1c8.315fe32.mid.smarden.org","subject":"Re: [PATCH] git-clone.sh: properly configure remote even if remote's head is dangling","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-02-20T15:18:37Z","receivedAt":"2008-02-20T15:18:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 20 Feb 2008, Gerrit Pape wrote:\n\n> When cloning a remote repository which's HEAD refers to a nonexistent \n> ref, git-clone cloned all existing refs, but failed to write the \n> configuration for 'remote'.  Now it detects the dangling remote HEAD, \n> refuses to checkout any local branch since HEAD refers to nowhere, but \n> properly writes the configuration for 'remote', so that subsequent 'git \n> fetch's don't fail.\n\nI like your reasoning, and your patch.  Except maybe...\n\n> diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh\n> index 822ac8c..59a165a 100755\n> --- a/t/t5701-clone-local.sh\n> +++ b/t/t5701-clone-local.sh\n> @@ -63,4 +63,12 @@ test_expect_success 'Even without -l, local will make a hardlink' '\n>  \ttest 0 = $copied\n>  '\n>  \n> +test_expect_success 'local clone of repo with nonexistent ref in HEAD' '\n> +\tcd \"$D\" &&\n\n... making this a subshell would be nice, so that subsequent tests start \nout from trash/ again?\n\nCiao,\nDscho\n"},{"id":"69401","messageId":"7vbq6b4c27.fsf@gitster.siamese.dyndns.org","threadId":"12215","inReplyTo":"20080220151017.17840.qmail@767a223c93e1c8.315fe32.mid.smarden.org","subject":"Re: [PATCH] git-clone.sh: properly configure remote even if remote's head is dangling","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-20T20:17:52Z","receivedAt":"2008-02-20T20:17:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Gerrit Pape <pape@smarden.org> writes:\n\n> When cloning a remote repository which's HEAD refers to a nonexistent\n> ref, git-clone cloned all existing refs, but failed to write the\n> configuration for 'remote'.  Now it detects the dangling remote HEAD,\n> refuses to checkout any local branch since HEAD refers to nowhere, but\n> properly writes the configuration for 'remote', so that subsequent\n> 'git fetch's don't fail.\n\nThe patch looks Ok, thanks.\n\nBy the way, I am still waiting for an ack/nack to my butchering\nof your earlier \"hash-object\" patch.\n\n  http://thread.gmane.org/gmane.comp.version-control.git/73811/focus=73964\n  Message-Id: <7vskzugm8x.fsf@gitster.siamese.dyndns.org>\n"}]}