# [PATCH] git-clone: Better handling of failed fetches of HEAD over HTTP

2 messages from 2007-04-12 to 2007-04-12. Participants: Martin Langhoff, Karl Hasselström.
Thread: https://gitlist.dev/t/7625

## Martin Langhoff, 2007-04-12 09:25

Subject: [PATCH] git-clone: Better handling of failed fetches of HEAD over HTTP
Message-ID: <11763699332101-git-send-email-martin@catalyst.net.nz>
URL: https://gitlist.dev/e/11763699332101-git-send-email-martin%40catalyst.net.nz

```
Junio said:
> Why not default to 'master' (if found) and issue a warning?

A common problem when cloning over http is that the repo has
a symlink for HEAD, and apache refuses to serve symlinks by
default.

With this patch, the clone will fallback to trying to get
refs/heads/master -- which often works. If it cannot get
HEAD or refs/heads/master, then it will die, aborting the clone.

Signed-off-by: Martin Langhoff <martin@catalyst.net.nz>
---
 git-clone.sh |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index 513b574..e98e064 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -64,7 +64,14 @@ Perhaps git-update-server-info needs to be run there?"
 	done <"$clone_tmp/refs"
 	rm -fr "$clone_tmp"
 	http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
-	rm -f "$GIT_DIR/REMOTE_HEAD"
+		(echo "Could not get "$1/HEAD", perhaps it is a symlink: trying with refs/heads/master" &&
+		http_fetch "$1/refs/heads/master" "$GIT_DIR/REMOTE_HEAD") ||
+		rm -f "$GIT_DIR/REMOTE_HEAD"
+
+	if test ! -f "$GIT_DIR/REMOTE_HEAD"
+	then
+		die "Could not retrieve $1/HEAD nor $1/refs/heads/master ."
+	fi
 }
 
 quiet=
-- 
1.5.1.106.ga32037

```

## Karl Hasselström, 2007-04-12 11:38

Subject: Re: [PATCH] git-clone: Better handling of failed fetches of HEAD over HTTP
Message-ID: <20070412113830.GA26445@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20070412113830.GA26445%40diana.vm.bytemark.co.uk
In-Reply-To: <11763699332101-git-send-email-martin@catalyst.net.nz>

```
On 2007-04-12 21:25:33 +1200, Martin Langhoff wrote:

> +		die "Could not retrieve $1/HEAD nor $1/refs/heads/master ."

The "nor" should be just "or", I believe. Otherwise, this would have
to be

  Could retrieve neither foo nor bar.

which sounds a bit too formal. But a native English speaker should
probably verify that my advice is correct.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```
