|
| 1 | +# Both example.net/ambiguous v0.1.0 and example.net/ambiguous/pkg v0.1.0 exist. |
| 2 | +# 'go mod tidy' would arbitrarily choose the one with the longer path, |
| 3 | +# but 'go mod tidy' also arbitrarily chooses the latest version. |
| 4 | + |
| 5 | +cp go.mod go.mod.orig |
| 6 | + |
| 7 | + |
| 8 | +# From a clean slate, 'go get' currently does the same thing as 'go mod tidy': |
| 9 | +# it resolves the package from the module with the longest matching prefix. |
| 10 | + |
| 11 | +go get -d example.net/ambiguous/nested/ [email protected] |
| 12 | +go list -m all |
| 13 | +stdout '^example.net/ambiguous/nested v0.1.0$' |
| 14 | +! stdout '^example.net/ambiguous ' |
| 15 | + |
| 16 | + |
| 17 | +# From an initial state that already depends on the shorter path, |
| 18 | +# the same 'go get' command attempts to add the longer path and fails. |
| 19 | +# |
| 20 | +# TODO(bcmills): What should really happen here? |
| 21 | +# Should we match the versioned package path against the existing package |
| 22 | +# (reducing unexpected errors), or give it the same meaning regardless of the |
| 23 | +# initial state? |
| 24 | + |
| 25 | +cp go.mod.orig go.mod |
| 26 | +go mod edit -require=example.net/ [email protected] |
| 27 | + |
| 28 | +! go get -d example.net/ambiguous/nested/ [email protected] |
| 29 | +stderr '^go get example.net/ambiguous/nested/ [email protected]: ambiguous import: found package example.net/ambiguous/nested/pkg in multiple modules:\n\texample.net/ambiguous v0.1.0 \(.*\)\n\texample.net/ambiguous/nested v0.1.0 \(.*\)\n\z' |
| 30 | + |
| 31 | + |
| 32 | +# The user should be able to fix the aforementioned failure by explicitly |
| 33 | +# upgrading the conflicting module. |
| 34 | + |
| 35 | +go get -d example.net/ [email protected] example.net/ambiguous/nested/ [email protected] |
| 36 | +go list -m all |
| 37 | +stdout '^example.net/ambiguous/nested v0.1.0$' |
| 38 | +stdout '^example.net/ambiguous v0.2.0$' |
| 39 | + |
| 40 | + |
| 41 | +# ...or by explicitly NOT adding the conflicting module. |
| 42 | +# |
| 43 | +# BUG(#37438): Today, this does not work: explicit module version constraints do |
| 44 | +# not affect the package-to-module mapping during package upgrades, so the |
| 45 | +# arguments are interpreted as specifying conflicting versions of the longer |
| 46 | +# module path. |
| 47 | + |
| 48 | +cp go.mod.orig go.mod |
| 49 | +go mod edit -require=example.net/ [email protected] |
| 50 | + |
| 51 | +! go get -d example.net/ambiguous/nested/ [email protected] example.net/ambiguous/nested@none |
| 52 | +stderr '^go get: conflicting versions for module example.net/ambiguous/nested: v0.1.0 and none$' |
| 53 | + |
| 54 | + # go list -m all |
| 55 | + # ! stdout '^example.net/ambiguous/nested ' |
| 56 | + # stdout '^example.net/ambiguous v0.1.0$' |
| 57 | + |
| 58 | + |
| 59 | +# The user should also be able to fix it by *downgrading* the conflicting module |
| 60 | +# away. |
| 61 | +# |
| 62 | +# BUG(#37438): Today, this does not work: the "ambiguous import" error causes |
| 63 | +# 'go get' to fail before applying the requested downgrade. |
| 64 | + |
| 65 | +cp go.mod.orig go.mod |
| 66 | +go mod edit -require=example.net/ [email protected] |
| 67 | + |
| 68 | +! go get -d example.net/ambiguous@none example.net/ambiguous/nested/ [email protected] |
| 69 | +stderr '^go get example.net/ambiguous/nested/ [email protected]: ambiguous import: found package example.net/ambiguous/nested/pkg in multiple modules:\n\texample.net/ambiguous v0.1.0 \(.*\)\n\texample.net/ambiguous/nested v0.1.0 \(.*\)\n\z' |
| 70 | + |
| 71 | + # go list -m all |
| 72 | + # stdout '^example.net/ambiguous/nested v0.1.0$' |
| 73 | + # !stdout '^example.net/ambiguous ' |
| 74 | + |
| 75 | + |
| 76 | +# In contrast, if we do the same thing tacking a wildcard pattern ('/...') on |
| 77 | +# the end of the package path, we get different behaviors depending on the |
| 78 | +# initial state, and no error. (This seems to contradict the “same meaning |
| 79 | +# regardless of the initial state” point above, but maybe that's ok?) |
| 80 | + |
| 81 | +cp go.mod.orig go.mod |
| 82 | + |
| 83 | +go get -d example.net/ambiguous/nested/pkg/ [email protected] |
| 84 | +go list -m all |
| 85 | +stdout '^example.net/ambiguous/nested v0.1.0$' |
| 86 | +! stdout '^example.net/ambiguous ' |
| 87 | + |
| 88 | + |
| 89 | +cp go.mod.orig go.mod |
| 90 | +go mod edit -require=example.net/ [email protected] |
| 91 | + |
| 92 | +go get -d example.net/ambiguous/nested/pkg/ [email protected] |
| 93 | +go list -m all |
| 94 | +! stdout '^example.net/ambiguous/nested ' |
| 95 | +stdout '^example.net/ambiguous v0.1.0$' |
| 96 | + |
| 97 | + |
| 98 | +-- go.mod -- |
| 99 | +module test |
| 100 | + |
| 101 | +go 1.16 |
0 commit comments