git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
MLMartin Langhoff <martin@catalyst.net.nz>
Date
Apr 12, 2007, 09:25 UTC
Message-ID
<11763699332101-git-send-email-martin@catalyst.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
Next: Karl Hasselström
Message 1 of 2 in “git-clone: Better handling of failed fetches of HEAD over HTTP”
  1. git-clone: Better handling of failed fetches of HEAD over HTTPMartin Langhoff, Apr 12, 2007
  2. Karl HasselströmApr 12, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.