From 4b4cd5aa8d343086a6e95ca5492ec6db931e6b30 Mon Sep 17 00:00:00 2001 From: Dave MacFarlane Date: Sun, 14 Oct 2018 15:44:42 -0400 Subject: [PATCH] Use same $GIT_URL for upload-pack and ref discovery The refsSuffix used for reference discovery appends ".git" to the repo name, while the upload pack proxying does not. This can result in a 422 response from GitHub instead of a packfile when trying to clone gopkg.in repos (ie driusan/dgit#129), making gopkg.in URLs uncloneable with some third party git clients. I'm not sure why GitHub doesn't have this issue when cloning with the official git client, but using the same base git url for both /info/refs and /git-upload-pack appears to fix the issue for dgit while not causing any noticeable regressions with real git when I tested this change locally. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 67eac82..0d88177 100644 --- a/main.go +++ b/main.go @@ -353,7 +353,7 @@ func sendNotFound(resp http.ResponseWriter, msg string, args ...interface{}) { const refsSuffix = ".git/info/refs?service=git-upload-pack" func proxyUploadPack(resp http.ResponseWriter, req *http.Request, repo *Repo) { - preq, err := http.NewRequest(req.Method, "https://"+repo.GitHubRoot()+"/git-upload-pack", req.Body) + preq, err := http.NewRequest(req.Method, "https://"+repo.GitHubRoot()+".git/git-upload-pack", req.Body) if err != nil { resp.WriteHeader(http.StatusInternalServerError) resp.Write([]byte(fmt.Sprintf("Cannot create GitHub request: %v", err)))