-
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: propagate origin information for inexact module queries
Module queries for "@latest" and inexact constraints (like "@v1.3") may consult information about tags and/or branches before finally returning either a result or an error. To correctly invalidate the origin information for the -reuse flag, the reported Origin needs to reflect all of those inputs. Fixes #61415. Change-Id: I054acbef7d218a92a3bbb44517326385e458d907 Reviewed-on: https://go-review.googlesource.com/c/go/+/542717 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
- Loading branch information
Showing
6 changed files
with
211 additions
and
59 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,76 @@ | ||
[short] skip 'generates a vcstest git repo' | ||
[!git] skip | ||
|
||
env GOPROXY=direct | ||
|
||
# Control case: fetching a nested module at a tag that exists should | ||
# emit Origin metadata for that tag and commit, and the origin should | ||
# be reusable for that tag. | ||
|
||
go list -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@has-nested | ||
cp stdout has-nested.json | ||
stdout '"Origin":' | ||
stdout '"VCS": "git"' | ||
stdout '"URL":' # randomly-chosen vcweb localhost URL | ||
stdout '"Subdir": "nested"' | ||
stdout '"TagPrefix": "nested/"' | ||
stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' | ||
stdout '"Ref": "refs/tags/has-nested"' | ||
stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' | ||
|
||
go list -reuse=has-nested.json -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@has-nested | ||
stdout '"Origin":' | ||
stdout '"VCS": "git"' | ||
stdout '"URL":' # randomly-chosen vcweb localhost URL | ||
stdout '"Subdir": "nested"' | ||
stdout '"TagPrefix": "nested/"' | ||
stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' | ||
stdout '"Ref": "refs/tags/has-nested"' | ||
stdout '"Hash": "08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a"' | ||
stdout '"Reuse": true' | ||
|
||
|
||
# Experiment case: if the nested module doesn't exist at "latest", | ||
# the Origin metadata should include the ref that we tried to resolve | ||
# (HEAD for a repo without version tags) and the hash to which it refers, | ||
# so that changing the HEAD ref will invalidate the result. | ||
|
||
go list -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@latest | ||
cp stdout no-nested.json | ||
stdout '"Err": "module vcs-test.golang.org/git/issue61415.git/nested: no matching versions for query \\"latest\\""' | ||
stdout '"URL":' # randomly-chosen vcweb localhost URL | ||
stdout '"Subdir": "nested"' | ||
stdout '"TagPrefix": "nested/"' | ||
stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' | ||
|
||
stdout '"Ref": "HEAD"' | ||
stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' | ||
|
||
# The error result should be reusable. | ||
|
||
go list -reuse=no-nested.json -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@latest | ||
|
||
stdout '"Err": "module vcs-test.golang.org/git/issue61415.git/nested: no matching versions for query \\"latest\\""' | ||
stdout '"URL":' # randomly-chosen vcweb localhost URL | ||
stdout '"Subdir": "nested"' | ||
stdout '"TagPrefix": "nested/"' | ||
stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' | ||
stdout '"Ref": "HEAD"' | ||
stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' | ||
stdout '"Reuse": true' | ||
|
||
|
||
# If the hash refers to some other commit instead, the | ||
# result should not be reused. | ||
|
||
replace f213069baa68ec26412fb373c7cf6669db1f8e69 08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a no-nested.json | ||
|
||
go list -reuse=no-nested.json -json -m --versions -e vcs-test.golang.org/git/issue61415.git/nested@latest | ||
stdout '"Err": "module vcs-test.golang.org/git/issue61415.git/nested: no matching versions for query \\"latest\\""' | ||
stdout '"URL":' # randomly-chosen vcweb localhost URL | ||
stdout '"Subdir": "nested"' | ||
stdout '"TagPrefix": "nested/"' | ||
stdout '"TagSum": "t1:47DEQpj8HBSa\+/TImW\+5JCeuQeRkm5NMpJWZG3hSuFU="' | ||
stdout '"Ref": "HEAD"' | ||
stdout '"Hash": "f213069baa68ec26412fb373c7cf6669db1f8e69"' | ||
! stdout '"Reuse"' |
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,42 @@ | ||
handle git | ||
|
||
env GIT_AUTHOR_NAME='Bryan C. Mills' | ||
env GIT_AUTHOR_EMAIL='[email protected]' | ||
env GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME | ||
env GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL | ||
|
||
at 2023-11-14T13:00:00-05:00 | ||
|
||
git init | ||
|
||
git add go.mod nested | ||
git commit -m 'nested: add go.mod' | ||
git branch -m main | ||
|
||
git tag has-nested | ||
|
||
at 2023-11-14T13:00:01-05:00 | ||
|
||
git rm -r nested | ||
git commit -m 'nested: delete subdirectory' | ||
|
||
git show-ref --tags --heads | ||
cmp stdout .git-refs | ||
|
||
git log --pretty=oneline | ||
cmp stdout .git-log | ||
|
||
-- .git-refs -- | ||
f213069baa68ec26412fb373c7cf6669db1f8e69 refs/heads/main | ||
08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a refs/tags/has-nested | ||
-- .git-log -- | ||
f213069baa68ec26412fb373c7cf6669db1f8e69 nested: delete subdirectory | ||
08a4fa6bb9c04ffba03b26ae427b0d6335d90a2a nested: add go.mod | ||
-- go.mod -- | ||
module vcs-test.golang.org/git/issue61415.git | ||
|
||
go 1.20 | ||
-- nested/go.mod -- | ||
module vcs-test.golang.org/git/issue61415.git/nested | ||
|
||
go 1.20 |