-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: check that expected Origin fields are present to reuse module…
… info When 'go list' or 'go mod download' uses a proxy to resolve a version query like "@latest", it may have origin metadata about the resolved version but not about the inputs that would be needed to resolve the same query without using the proxy. We shouldn't just redact the incomplete information, because it might be useful independent of the -reuse flag. Instead, we examine the query to decide which origin information it ought to need, and avoid reusing it if that information isn't included. Fixes #61423. Change-Id: Ibeaa46ebba284beee285cbb1898e271e5a5b257b Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/543155 Reviewed-by: Michael Matloob <[email protected]> Commit-Queue: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
- Loading branch information
Showing
4 changed files
with
176 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
[short] skip 'generates a vcstest git repo' | ||
[!git] skip | ||
|
||
mkdir $WORK/mod1 | ||
mkdir $WORK/mod2 | ||
env GONOSUMDB=vcs-test.golang.org | ||
|
||
env GOPROXY=direct | ||
env GOMODCACHE=$WORK/mod1 | ||
|
||
|
||
# If we query a module version from a git repo, we expect its | ||
# Origin data to be reusable. | ||
|
||
go list -m -json vcs-test.golang.org/git/issue61415.git@latest | ||
cp stdout git-latest.json | ||
stdout '"Version": "v0.0.0-20231114180001-f213069baa68"' | ||
stdout '"Origin":' | ||
stdout '"VCS": "git"' | ||
stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' | ||
stdout '"Ref": "HEAD"' | ||
stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' | ||
|
||
go list -reuse=git-latest.json -m -json vcs-test.golang.org/git/issue61415.git@latest | ||
stdout '"Version": "v0.0.0-20231114180001-f213069baa68"' | ||
stdout '"Origin":' | ||
stdout '"VCS": "git"' | ||
stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' | ||
stdout '"Ref": "HEAD"' | ||
stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' | ||
stdout '"Reuse": true' | ||
|
||
|
||
# Now we construct a filesystem-based module proxy that | ||
# contains only an older commit. | ||
|
||
go clean -modcache | ||
|
||
go mod download -json vcs-test.golang.org/git/issue61415.git@08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a | ||
stdout '"Version": "v0.0.0-20231114180000-08a4fa6bb9c0"' | ||
stdout '"Origin":' | ||
stdout '"VCS": "git"' | ||
stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' | ||
|
||
[GOOS:windows] env GOPROXY=file:///$WORK/mod1/cache/download | ||
[!GOOS:windows] env GOPROXY=file://$WORK/mod1/cache/download | ||
env GOMODCACHE=$WORK/modcache2 | ||
|
||
|
||
# If we resolve the "latest" version query using a proxy, | ||
# it is only going to have Git origin information about the one | ||
# commit — not the other tags that would go into resolving | ||
# the underlying version list. | ||
|
||
go list -m -json vcs-test.golang.org/git/issue61415.git@latest | ||
cp stdout proxy-latest.json | ||
stdout '"Version": "v0.0.0-20231114180000-08a4fa6bb9c0"' | ||
stdout '"Origin":' | ||
stdout '"VCS": "git"' | ||
stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' | ||
! stdout '"Ref":' | ||
! stdout '"TagSum":' | ||
|
||
# The -reuse flag has no effect with a proxy, since the proxy can serve | ||
# metadata about a given module version cheaply anyway. | ||
go list -reuse=proxy-latest.json -m -json vcs-test.golang.org/git/issue61415.git@latest | ||
stdout '"Version": "v0.0.0-20231114180000-08a4fa6bb9c0"' | ||
stdout '"Origin":' | ||
stdout '"VCS": "git"' | ||
stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' | ||
! stdout '"Ref":' | ||
! stdout '"TagSum":' | ||
! stdout '"Reuse":' | ||
|
||
|
||
# With GOPROXY=direct, the -reuse flag has an effect, but | ||
# the Origin data from the proxy should not be sufficient | ||
# for the proxy response to be reused. | ||
|
||
env GOPROXY=direct | ||
|
||
go list -reuse=proxy-latest.json -m -json vcs-test.golang.org/git/issue61415.git@latest | ||
stdout '"Version": "v0.0.0-20231114180001-f213069baa68"' | ||
stdout '"Origin":' | ||
stdout '"VCS": "git"' | ||
stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' | ||
stdout '"Ref": "HEAD"' | ||
stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' | ||
! stdout '"Reuse":' |