From 2be698cef0cd8d971fbb4b4d0d7eef0f24aa649e Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 4 Nov 2021 11:23:41 -0400 Subject: cmd/golangorg: provide helpful error for git clone https://golang.org/x/repo People try git clone https://golang.org/x/website (for example) to clone the website repo. Tell them the right command. Change-Id: I7dc32190c959afff9908dde0727837b068bfecba Reviewed-on: https://go-review.googlesource.com/c/website/+/361203 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Go Bot Reviewed-by: Dmitri Shuralyov --- cmd/golangorg/server.go | 9 +++++++++ cmd/golangorg/testdata/x.txt | 4 ++++ 2 files changed, 13 insertions(+) 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. -- cgit v1.3