err := modfetch.TryProxies(func(proxy string) error {
queryModule := func(path string) (r QueryResult, err error) {
+ current := findCurrentVersion(path)
r.Mod.Path = path
- r.Rev, err = queryProxy(proxy, path, query, "", allowed)
+ r.Rev, err = queryProxy(proxy, path, query, current, allowed)
if err != nil {
return r, err
}
return prefixes
}
+func findCurrentVersion(path string) string {
+ for _, m := range buildList {
+ if m.Path == path {
+ return m.Version
+ }
+ }
+ return ""
+}
+
type prefixResult struct {
QueryResult
err error
--- /dev/null
+Module example.com/incompatiblewithsub has an incompatible version
+and a package in a subdirectory.
+-- .info --
+{"Version":"v1.0.0"}
+-- .mod --
+module example.com/incompatiblewithsub
+-- sub/sub.go --
+package sub
--- /dev/null
+Module example.com/incompatiblewithsub has an incompatible version
+and a package in a subdirectory.
+-- .info --
+{"Version":"v2.0.0+incompatible"}
+-- .mod --
+module example.com/incompatiblewithsub
+-- sub/sub.go --
+package sub
--- /dev/null
+# Verifies golang.org/issue/37574.
+
+# If we are already using an +incompatible version, we shouldn't look up
+# a lower compatible version when upgrading.
+cp go.mod go.mod.orig
+go mod tidy
+cmp go.mod.orig go.mod
+grep '^example.com/incompatiblewithsub v2\.0\.0\+incompatible' go.sum
+! grep '^example.com/incompatiblewithsub v1.0.0' go.sum
+
+go get -d example.com/incompatiblewithsub/sub
+cmp go.mod.orig go.mod
+! grep '^example.com/incompatiblewithsub v1.0.0' go.sum
+
+# TODO(golang.org/issue/31580): the 'go get' command above should not change
+# go.sum. However, as part of the query above, we download example.com@v1.0.0,
+# an unrelated module, since it's a possible prefix. The sum for that module
+# should not be written to go.sum.
+
+-- go.mod --
+module m
+
+go 1.15
+
+require example.com/incompatiblewithsub v2.0.0+incompatible
+-- use.go --
+package use
+
+import _ "example.com/incompatiblewithsub/sub"