diff options
| -rw-r--r-- | cmd/golangorg/server.go | 9 | ||||
| -rw-r--r-- | cmd/golangorg/testdata/x.txt | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go index 905e018e..b1a9d04e 100644 --- a/cmd/golangorg/server.go +++ b/cmd/golangorg/server.go @@ -507,6 +507,15 @@ func xHandler(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } + if suffix == "/info/refs" && strings.HasPrefix(r.URL.Query().Get("service"), "git-") && repo.GoGerritProject != "" { + // Someone is running 'git clone https://golang.org/x/repo'. + // We want the eventual git checkout to have the right origin (go.googlesource.com) + // and not just keep hitting golang.org all the time. + // A redirect would work for this git command but not record the result. + // Instead, print a useful error for the user. + http.Error(w, fmt.Sprintf("Use 'git clone https://go.googlesource.com/%s' instead.", repo.GoGerritProject), http.StatusNotFound) + return + } data := struct { Proj string // Gerrit project ("net", "sys", etc) Suffix string // optional "/path" for requests like /x/PROJ/path diff --git a/cmd/golangorg/testdata/x.txt b/cmd/golangorg/testdata/x.txt index 24233871..29d7d491 100644 --- a/cmd/golangorg/testdata/x.txt +++ b/cmd/golangorg/testdata/x.txt @@ -23,3 +23,7 @@ header location == https://pkg.go.dev/search?q=golang.org/x GET https://golang.org/x/In%20Valid,X code == 404 + +GET https://golang.org/x/website/info/refs?service=git-upload-pack +code == 404 +body contains Use 'git clone https://go.googlesource.com/website' instead. |
