Skip to content

Commit 9a40dee

Browse files
author
Bryan C. Mills
committed
cmd/go: reject 'go list -m MOD@patch' when no existing version of MOD is required
Noticed while debugging failing tests for #36460. Fixes #44788 Change-Id: Ic2cf511d871b29284f7372920f6f7d452825dd63 Reviewed-on: https://go-review.googlesource.com/c/go/+/298651 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent a416efe commit 9a40dee

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/cmd/go/internal/modload/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func listModules(ctx context.Context, args []string, listVersions, listRetracted
7878
if i := strings.Index(arg, "@"); i >= 0 {
7979
path := arg[:i]
8080
vers := arg[i+1:]
81-
var current string
81+
current := "none"
8282
for _, m := range buildList {
8383
if m.Path == path {
8484
current = m.Version

src/cmd/go/internal/modload/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func newQueryMatcher(path string, query, current string, allowed AllowedFunc) (*
330330
}
331331

332332
case query == "patch":
333-
if current == "none" {
333+
if current == "" || current == "none" {
334334
return nil, &NoPatchBaseError{path}
335335
}
336336
if current == "" {

src/cmd/go/internal/modload/query_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ var queryTests = []struct {
122122
{path: queryRepo, query: "upgrade", allow: "NOMATCH", err: `no matching versions for query "upgrade"`},
123123
{path: queryRepo, query: "upgrade", current: "v1.9.9", allow: "NOMATCH", err: `vcs-test.golang.org/git/[email protected]: disallowed module version`},
124124
{path: queryRepo, query: "upgrade", current: "v1.99.99", err: `vcs-test.golang.org/git/[email protected]: invalid version: unknown revision v1.99.99`},
125-
{path: queryRepo, query: "patch", current: "", vers: "v1.9.9"},
125+
{path: queryRepo, query: "patch", current: "", err: `can't query version "patch" of module vcs-test.golang.org/git/querytest.git: no existing version is required`},
126126
{path: queryRepo, query: "patch", current: "v0.1.0", vers: "v0.1.2"},
127127
{path: queryRepo, query: "patch", current: "v1.9.0", vers: "v1.9.9"},
128128
{path: queryRepo, query: "patch", current: "v1.9.10-pre1", vers: "v1.9.10-pre1"},

src/cmd/go/testdata/script/mod_prefer_compatible.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ stdout '^github.com/russross/blackfriday v1\.'
2323
go list -m github.com/russross/blackfriday@upgrade
2424
stdout '^github.com/russross/blackfriday v1\.'
2525

26-
go list -m github.com/russross/blackfriday@patch
27-
stdout '^github.com/russross/blackfriday v1\.'
26+
! go list -m github.com/russross/blackfriday@patch
27+
stderr '^go list -m: github.com/russross/blackfriday@patch: can''t query version "patch" of module github.com/russross/blackfriday: no existing version is required$'
2828

2929
# If we're fetching directly from version control, ignored +incompatible
3030
# versions should also be omitted by 'go list'.

0 commit comments

Comments
 (0)