aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modfetch/codehost/git.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2019-04-30 13:07:05 -0400
committerRuss Cox <rsc@golang.org>2019-04-30 20:22:30 +0000
commit70b890ce3b72fdab528ee1f93b1950173e9a0992 (patch)
treec6009f64ea1737a1e67968e5a8e7b5d6ab1ac925 /src/cmd/go/internal/modfetch/codehost/git.go
parent8bde43e0694ed91565c95b286e3d31a2f43d8d80 (diff)
downloadgo-70b890ce3b72fdab528ee1f93b1950173e9a0992.tar.gz
go-70b890ce3b72fdab528ee1f93b1950173e9a0992.zip
cmd/go/internal/modfetch/codehost: disable fetch of server-resolved commit hash
We cannot rely on the server to filter out the refs we don't want (we only want refs/heads/* and refs/tags/*), so do not give it the full hash. Fixes #31191. Change-Id: If1208c35954228aa6e8734f8d5f1725d0ec79c87 Reviewed-on: https://go-review.googlesource.com/c/go/+/174517 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modfetch/codehost/git.go')
-rw-r--r--src/cmd/go/internal/modfetch/codehost/git.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go
index 2cb6637aae..5273e633b5 100644
--- a/src/cmd/go/internal/modfetch/codehost/git.go
+++ b/src/cmd/go/internal/modfetch/codehost/git.go
@@ -32,7 +32,7 @@ func LocalGitRepo(remote string) (Repo, error) {
return newGitRepoCached(remote, true)
}
-const gitWorkDirType = "git2"
+const gitWorkDirType = "git3"
var gitRepoCache par.Cache
@@ -339,8 +339,14 @@ func (r *gitRepo) stat(rev string) (*RevInfo, error) {
}
}
- // If we know a specific commit we need, fetch it.
- if r.fetchLevel <= fetchSome && hash != "" && !r.local {
+ // If we know a specific commit we need and its ref, fetch it.
+ // We do NOT fetch arbitrary hashes (when we don't know the ref)
+ // because we want to avoid ever importing a commit that isn't
+ // reachable from refs/tags/* or refs/heads/* or HEAD.
+ // Both Gerrit and GitHub expose every CL/PR as a named ref,
+ // and we don't want those commits masquerading as being real
+ // pseudo-versions in the main repo.
+ if r.fetchLevel <= fetchSome && ref != "" && hash != "" && !r.local {
r.fetchLevel = fetchSome
var refspec string
if ref != "" && ref != "HEAD" {