1 cp go.mod go.mod.orig
2
3
4 # 'go get' on a package already provided by the build list should update
5 # the module already in the build list, not fail with an ambiguous import error.
6
7 go get example.net/split/nested@patch
8 go list -m all
9 stdout '^example.net/split v0.2.1 '
10 ! stdout '^example.net/split/nested'
11
12 # We should get the same behavior if we use a pattern that matches only that package.
13
14 cp go.mod.orig go.mod
15
16 go get example.net/split/nested/...@patch
17 go list -m all
18 stdout '^example.net/split v0.2.1 '
19 ! stdout '^example.net/split/nested'
20
21
22 # If we request a version for which the package only exists in one particular module,
23 # we should add that one particular module but not resolve import ambiguities.
24 #
25 # In particular, if the module that previously provided the package has a
26 # matching version, but does not itself match the pattern and contains no
27 # matching packages, we should not change its version. (We should *not* downgrade
28 # module example.net/split to v0.1.0, despite the fact that
29 # example.net/split v0.2.0 currently provides the package with the requested path.)
30 #
31 # TODO(#27899): Maybe we should resolve the ambiguities by upgrading.
32
33 cp go.mod.orig go.mod
34
35 ! go get example.net/split/nested@v0.1.0
36 stderr '^go: example.net/split/nested: ambiguous import: found package example.net/split/nested in multiple modules:\n\texample.net/split v0.2.0 \(.*split.2[/\\]nested\)\n\texample.net/split/nested v0.1.0 \(.*nested.1\)$'
37
38 # A wildcard that matches packages in some module at its selected version
39 # but not at the requested version should fail.
40 #
41 # We can't set the module to the selected version, because that version doesn't
42 # even match the query: if we ran the same query twice, we wouldn't consider the
43 # module to match the wildcard during the second call, so why should we consider
44 # it to match during the first one? ('go get' should be idempotent, and if we
45 # did that then it would not be.)
46 #
47 # But we also can't leave it where it is: the user requested that we set everything
48 # matching the pattern to the given version, and right now we have packages
49 # that match the pattern but *not* the version.
50 #
51 # That only leaves two options: we can set the module to an arbitrary version
52 # (perhaps 'latest' or 'none'), or we can report an error and the let the user
53 # disambiguate. We would rather not choose arbitrarily, so we do the latter.
54 #
55 # TODO(#27899): Should we instead upgrade or downgrade to an arbitrary version?
56
57 ! go get example.net/split/nested/...@v0.1.0
58 stderr '^go: example.net/split/nested/\.\.\.@v0.1.0 matches packages in example.net/split@v0.2.0 but not example.net/split@v0.1.0: specify a different version for module example.net/split$'
59
60 cmp go.mod go.mod.orig
61
62
63 # If another argument resolves the ambiguity, we should be ok again.
64
65 go get example.net/split@none example.net/split/nested@v0.1.0
66 go list -m all
67 ! stdout '^example.net/split '
68 stdout '^example.net/split/nested v0.1.0 '
69
70 cp go.mod.orig go.mod
71
72 go get example.net/split@v0.3.0 example.net/split/nested@v0.1.0
73 go list -m all
74 stdout '^example.net/split v0.3.0 '
75 stdout '^example.net/split/nested v0.1.0 '
76
77
78 # If a pattern applies to modules and to packages, we should set all matching
79 # modules to the version indicated by the pattern, and also resolve packages
80 # to match the pattern if possible.
81
82 cp go.mod.orig go.mod
83 go get example.net/split/nested@v0.0.0
84
85 go get example.net/...@v0.1.0
86 go list -m all
87 stdout '^example.net/split v0.1.0 '
88 stdout '^example.net/split/nested v0.1.0 '
89
90 go get example.net/...
91 go list -m all
92 stdout '^example.net/split v0.3.0 '
93 stdout '^example.net/split/nested v0.2.0 '
94
95
96 # @none applies to all matching module paths,
97 # regardless of whether they contain any packages.
98
99 go get example.net/...@none
100 go list -m all
101 ! stdout '^example.net'
102
103 # Starting from no dependencies, a wildcard can resolve to an empty module with
104 # the same prefix even if it contains no packages.
105
106 go get example.net/...@none
107 go get example.net/split/...@v0.1.0
108 go list -m all
109 stdout '^example.net/split v0.1.0 '
110
111
112 -- go.mod --
113 module m
114
115 go 1.16
116
117 require example.net/split v0.2.0
118
119 replace (
120 example.net/split v0.1.0 => ./split.1
121 example.net/split v0.2.0 => ./split.2
122 example.net/split v0.2.1 => ./split.2
123 example.net/split v0.3.0 => ./split.3
124 example.net/split/nested v0.0.0 => ./nested.0
125 example.net/split/nested v0.1.0 => ./nested.1
126 example.net/split/nested v0.2.0 => ./nested.2
127 )
128 -- split.1/go.mod --
129 module example.net/split
130
131 go 1.16
132 -- split.2/go.mod --
133 module example.net/split
134
135 go 1.16
136 -- split.2/nested/nested.go --
137 package nested
138 -- split.3/go.mod --
139 module example.net/split
140
141 go 1.16
142 -- nested.0/go.mod --
143 module example.net/split/nested
144
145 go 1.16
146 -- nested.1/go.mod --
147 module example.net/split/nested
148
149 go 1.16
150 -- nested.1/nested.go --
151 package nested
152 -- nested.2/go.mod --
153 module example.net/split/nested
154
155 go 1.16
156 -- nested.2/nested.go --
157 package nested
158
View as plain text