threads / patch / 7625

patchgit-clone: Better handling of failed fetches of HEAD over HTTP

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

## tl;dr

2 messages between Apr 12, 2007 and Apr 12, 2007. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Martin Langhoff· Apr 12, 2007, 09:25 UTC · lore
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(-)
Show changes to git-clone.sh +8 −1
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· Apr 12, 2007, 11:38 UTC · re: Martin Langhoff · lore

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

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

← back to recent threads