]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.16] cmd/go/internal/modload: don't query when fixing canonical...
authorJay Conrod <jayconrod@google.com>
Thu, 25 Feb 2021 23:38:43 +0000 (18:38 -0500)
committerDmitri Shuralyov <dmitshur@golang.org>
Wed, 3 Mar 2021 17:58:41 +0000 (17:58 +0000)
If a canonical version is passed to fixVersion when loading the main
go.mod and that version don't match the module path's major version
suffix, don't call Query.

Query doesn't return a useful error in this case when the path is
malformed, for example, when it doens't have a dot in the first path
element. It's better to report the major version mismatch error.

Fixes #44496

Change-Id: I97b1f64aee894fa0db6fb637aa03a51357ee782c
Reviewed-on: https://go-review.googlesource.com/c/go/+/296590
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
(cherry picked from commit 5fafc0bbd4819578e58e5b9163981b0074ab0b01)
Reviewed-on: https://go-review.googlesource.com/c/go/+/297989
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/cmd/go/internal/modload/init.go
src/cmd/go/testdata/script/mod_retract_fix_version.txt

index bc8d17e0a5fb5934d93a09025a186d21a0cccb6b..4de5ac93032e2c6cf2ba49d9a54087e223871d09 100644 (file)
@@ -539,9 +539,10 @@ func fixVersion(ctx context.Context, fixed *bool) modfile.VersionFixer {
                        }
                }
                if vers != "" && module.CanonicalVersion(vers) == vers {
-                       if err := module.CheckPathMajor(vers, pathMajor); err == nil {
-                               return vers, nil
+                       if err := module.CheckPathMajor(vers, pathMajor); err != nil {
+                               return "", module.VersionError(module.Version{Path: path, Version: vers}, err)
                        }
+                       return vers, nil
                }
 
                info, err := Query(ctx, path, vers, "", nil)
index f8099ec93e38e416216eca5d84eab35745b65a2f..e45758b627016da1252ace1231bbf4bb11a6c881 100644 (file)
@@ -12,6 +12,18 @@ go mod tidy
 go list -m all
 cmp go.mod go.mod.want
 
+# If a retracted version doesn't match the module's major version suffx,
+# an error should be reported.
+! go mod edit -retract=v3.0.1
+stderr '^go mod: -retract=v3.0.1: version "v3.0.1" invalid: should be v2, not v3$'
+cp go.mod.mismatch-v2 go.mod
+! go list -m all
+stderr 'go.mod:3: retract rsc.io/quote/v2: version "v3.0.1" invalid: should be v2, not v3$'
+
+cp go.mod.mismatch-v1 go.mod
+! go list -m all
+stderr 'go.mod:3: retract rsc.io/quote: version "v3.0.1" invalid: should be v0 or v1, not v3$'
+
 -- go.mod --
 go 1.16
 
@@ -22,3 +34,15 @@ go 1.16
 retract v2.0.1
 
 module rsc.io/quote/v2
+-- go.mod.mismatch-v2 --
+go 1.16
+
+retract v3.0.1
+
+module rsc.io/quote/v2
+-- go.mod.mismatch-v1 --
+go 1.16
+
+retract v3.0.1
+
+module rsc.io/quote