@@ -34,14 +34,14 @@ exec git branch -m main
3434# Use a 0.0.0 pseudo-version when no tags are present.
3535go build
3636go version -m example$GOEXE
37- stdout '\s+mod\s+example\s+v0.0.0-20220719150700-b52f952448d2 \s+'
37+ stdout '\s+mod\s+example\s+v0.0.0-20220719150700-e7537ba8fd6d \s+'
3838rm example$GOEXE
3939
4040# Use a 0.0.0 pseudo-version if the current tag is not a valid semantic version.
4141exec git tag 1.0.1
4242go build
4343go version -m example$GOEXE
44- stdout '\s+mod\s+example\s+v0.0.0-20220719150700-b52f952448d2 \s+'
44+ stdout '\s+mod\s+example\s+v0.0.0-20220719150700-e7537ba8fd6d \s+'
4545rm example$GOEXE
4646
4747# Use the current tag which has a valid semantic version to stamp the version.
@@ -79,14 +79,14 @@ exec git commit -m 'commit 3'
7979# Use a pseudo-version when current commit doesn't match a tagged version.
8080go build
8181go version -m example$GOEXE
82- stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-deaeab06f7fe \s+'
82+ stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-b0226f18a7ae \s+'
8383rm example$GOEXE
8484
8585# Use pseudo+dirty when uncommitted changes are present.
8686mv README2 README3
8787go build
8888go version -m example$GOEXE
89- stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-deaeab06f7fe \+dirty\s+'
89+ stdout '\s+mod\s+example\s+v1.0.3-0.20220719150702-b0226f18a7ae \+dirty\s+'
9090rm example$GOEXE
9191
9292# Make sure we always use the previously tagged version to generate the pseudo-version at a untagged revision.
@@ -105,9 +105,83 @@ exec git tag v1.0.4
105105exec git checkout ':/commit 4'
106106go build
107107go version -m example$GOEXE
108- stdout '\s+mod\s+example\s+v1.0.3-0.20220719150703-2e239bf29c13 \s+'
108+ stdout '\s+mod\s+example\s+v1.0.3-0.20220719150703-2ebc76937b49 \s+'
109109rm example$GOEXE
110110
111+ # Create +incompatible module
112+ exec git checkout v1.0.4
113+ exec git rm go.mod
114+ exec git commit -m 'commit 6'
115+ exec git tag v2.0.0
116+ exec git checkout HEAD^ go.mod
117+ # And make the tree +dirty
118+ mv README4 README5
119+ go build
120+ go version -m example$GOEXE
121+ stdout '\s+mod\s+example\s+v2.0.0\+incompatible.dirty\s+'
122+ rm example$GOEXE
123+
124+ # Make sure v2 works as expected.
125+ exec git checkout v1.0.4
126+ go mod edit -module example/v2
127+ exec git add .
128+ exec git commit -m 'commit 7'
129+ exec git tag v2.1.1
130+ go build
131+ go version -m example$GOEXE
132+ stdout '\s+mod\s+example/v2\s+v2.1.1\s+'
133+ rm example$GOEXE
134+
135+ # v2+dirty
136+ mv README5 README6
137+ go build
138+ go version -m example$GOEXE
139+ stdout '\s+mod\s+example/v2\s+v2.1.1\+dirty\s+'
140+ rm example$GOEXE
141+
142+ # v2+pseudo
143+ exec git add .
144+ exec git commit -m 'commit 8'
145+ go build
146+ go version -m example$GOEXE
147+ stdout '\s+mod\s+example/v2\s+v2.1.2-0.20220719150704-0ebeb94ecde2\s+'
148+ rm example$GOEXE
149+
150+ # v2+pseudo+dirty
151+ mv README6 README7
152+ go build
153+ go version -m example$GOEXE
154+ stdout '\s+mod\s+example/v2\s+v2.1.2-0.20220719150704-0ebeb94ecde2\+dirty\s+'
155+ rm example$GOEXE
156+
157+ # modules in subdirectories should be stamped with the correct tag
158+ exec git add .
159+ cd subdir
160+ exec git commit -m 'commit 9'
161+ go build
162+ go version -m subdir$GOEXE
163+ # missing tag creates a pseudo version with v2.0.0
164+ stdout '\s+mod\s+example/subdir/v2\s+v2.0.0-20220719150704-fbef6799938f\s+'
165+ rm subdir$GOEXE
166+ # tag with subdir
167+ exec git tag subdir/v2.1.0
168+ go build
169+ go version -m subdir$GOEXE
170+ stdout '\s+mod\s+example/subdir/v2\s+v2.1.0\s+'
171+ # v2+dirty
172+ mv ../README7 README8
173+ go build
174+ go version -m subdir$GOEXE
175+ stdout '\s+mod\s+example/subdir/v2\s+v2.1.0\+dirty\s+'
176+ rm subdir$GOEXE
177+
178+ # modules in a subdirectory without a go.mod in the root should result in (devel)
179+ rm ../go.mod
180+ go build
181+ go version -m subdir$GOEXE
182+ stdout '\s+mod\s+example/subdir/v2\s+\(devel\)\s+'
183+ rm subdir$GOEXE
184+
111185-- $WORK/repo/go.mod --
112186module example
113187
@@ -120,6 +194,17 @@ func main() {
120194-- $WORK/copy/README --
121195hello
122196
197+ -- $WORK/repo/subdir/go.mod --
198+ module example/subdir/v2
199+
200+ go 1.18
201+
202+ -- $WORK/repo/subdir/main.go --
203+ package main
204+
205+ func main() {
206+ }
207+
123208-- $WORK/home/gopher/.gitconfig --
124209[user]
125210 name = Go Gopher
0 commit comments