aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-11-04 11:23:41 -0400
committerRuss Cox <rsc@golang.org>2021-11-06 12:35:55 +0000
commit2be698cef0cd8d971fbb4b4d0d7eef0f24aa649e (patch)
tree23a22d1e54b82f8aa262d3e0c97340ea6953eb83
parent70e627117c3a61f48f3fb93c566c9b50a2fe7171 (diff)
downloadgo-x-website-2be698cef0cd8d971fbb4b4d0d7eef0f24aa649e.tar.xz
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 <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
-rw-r--r--cmd/golangorg/server.go9
-rw-r--r--cmd/golangorg/testdata/x.txt4
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.