Skip to content

Commit 2ab9218

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
cmd/go/internal/modfetch: pass "-c" arguments to git before subcommands
I accidentally transposed the arguments in CL 556358, causing the shallow 'git fetch' attempt to always fail. That didn't break any tests because we fall back to a full fetch, which works for nearly all real Git servers, and we didn't have a test that checked for shallow fetches. Tested manually using: GOPROXY=direct go mod download -x -json gerrit.wikimedia.org/r/[email protected] (I'm still thinking about how to add a proper regression test.) Fixes #66147. Change-Id: I0bb17283bae856f369fd24f29375e507d0999933 Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64-longtest,gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/569422 Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent a18aa0e commit 2ab9218

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/cmd/go/internal/modfetch/codehost/git.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func (r *gitRepo) stat(ctx context.Context, rev string) (info *RevInfo, err erro
554554
// an apparent Git bug introduced in Git 2.21 (commit 61c771),
555555
// which causes the handler for protocol version 1 to sometimes miss
556556
// tags that point to the requested commit (see https://go.dev/issue/56881).
557-
_, err = Run(ctx, r.dir, "git", "fetch", "-f", "-c", "protocol.version=2", "--depth=1", r.remote, refspec)
557+
_, err = Run(ctx, r.dir, "git", "-c", "protocol.version=2", "fetch", "-f", "--depth=1", r.remote, refspec)
558558
release()
559559

560560
if err == nil {

src/cmd/go/testdata/script/reuse_git.txt

+22-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ env GOSUMDB=off
77

88
# go mod download with the pseudo-version should invoke git but not have a TagSum or Ref.
99
go mod download -x -json vcs-test.golang.org/git/[email protected]
10-
stderr 'git fetch'
10+
stderr 'git( .*)* fetch'
1111
cp stdout hellopseudo.json
1212
! stdout '"(Query|TagPrefix|TagSum|Ref)"'
1313
stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
@@ -18,7 +18,7 @@ go clean -modcache
1818

1919
# go mod download vcstest/hello should invoke git, print origin info
2020
go mod download -x -json vcs-test.golang.org/git/hello.git@latest
21-
stderr 'git fetch'
21+
stderr 'git( .*)* fetch'
2222
cp stdout hello.json
2323
stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
2424
stdout '"VCS": "git"'
@@ -33,13 +33,13 @@ stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
3333
# but still be careful not to include a TagSum or a Ref, especially not Ref set to HEAD,
3434
# which is easy to do when reusing the cached version from the @latest query.
3535
go mod download -x -json vcs-test.golang.org/git/[email protected]
36-
! stderr 'git fetch'
36+
! stderr 'git( .*)* fetch'
3737
cp stdout hellopseudo2.json
3838
cmpenv hellopseudo.json hellopseudo2.json
3939

4040
# go mod download vcstest/hello@hash needs to check TagSum to find pseudoversion base.
4141
go mod download -x -json vcs-test.golang.org/git/hello.git@fc3a09f3dc5c
42-
! stderr 'git fetch'
42+
! stderr 'git( .*)* fetch'
4343
cp stdout hellohash.json
4444
stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
4545
stdout '"Query": "fc3a09f3dc5c"'
@@ -98,7 +98,7 @@ stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
9898

9999
# go mod download vcstest/tagtests should invoke git, print origin info
100100
go mod download -x -json vcs-test.golang.org/git/tagtests.git@latest
101-
stderr 'git fetch'
101+
stderr 'git( .*)* fetch'
102102
cp stdout tagtests.json
103103
stdout '"Version": "v0.2.2"'
104104
stdout '"Query": "latest"'
@@ -135,7 +135,7 @@ stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
135135

136136
# go mod download vcstest/prefixtagtests should invoke git, print origin info
137137
go mod download -x -json vcs-test.golang.org/git/prefixtagtests.git/sub@latest
138-
stderr 'git fetch'
138+
stderr 'git( .*)* fetch'
139139
cp stdout prefixtagtests.json
140140
stdout '"Version": "v0.0.10"'
141141
stdout '"Query": "latest"'
@@ -154,12 +154,12 @@ cp stdout all.json
154154
# clean the module cache, make sure that makes go mod download re-run git fetch, clean again
155155
go clean -modcache
156156
go mod download -x -json vcs-test.golang.org/git/hello.git@latest
157-
stderr 'git fetch'
157+
stderr 'git( .*)* fetch'
158158
go clean -modcache
159159

160160
# reuse go mod download vcstest/hello result
161161
go mod download -reuse=hello.json -x -json vcs-test.golang.org/git/hello.git@latest
162-
! stderr 'git fetch'
162+
! stderr 'git( .*)* fetch'
163163
stdout '"Reuse": true'
164164
stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
165165
stdout '"VCS": "git"'
@@ -175,7 +175,7 @@ stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
175175

176176
# reuse go mod download vcstest/hello pseudoversion result
177177
go mod download -reuse=hellopseudo.json -x -json vcs-test.golang.org/git/[email protected]
178-
! stderr 'git fetch'
178+
! stderr 'git( .*)* fetch'
179179
stdout '"Reuse": true'
180180
stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
181181
stdout '"VCS": "git"'
@@ -186,7 +186,7 @@ stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
186186

187187
# reuse go mod download vcstest/hello@hash
188188
go mod download -reuse=hellohash.json -x -json vcs-test.golang.org/git/hello.git@fc3a09f3dc5c
189-
! stderr 'git fetch'
189+
! stderr 'git( .*)* fetch'
190190
stdout '"Reuse": true'
191191
stdout '"Query": "fc3a09f3dc5c"'
192192
stdout '"Version": "v0.0.0-20170922010558-fc3a09f3dc5c"'
@@ -199,7 +199,7 @@ stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
199199

200200
# reuse go mod download vcstest/hello/v9 error result
201201
! go mod download -reuse=hellov9.json -x -json vcs-test.golang.org/git/hello.git/v9@latest
202-
! stderr 'git fetch'
202+
! stderr 'git( .*)* fetch'
203203
stdout '"Reuse": true'
204204
stdout '"Error":.*no matching versions'
205205
! stdout '"TagPrefix"'
@@ -210,7 +210,7 @@ stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
210210

211211
# reuse go mod download vcstest/hello/sub/v9 error result
212212
! go mod download -reuse=hellosubv9.json -x -json vcs-test.golang.org/git/hello.git/sub/v9@latest
213-
! stderr 'git fetch'
213+
! stderr 'git( .*)* fetch'
214214
stdout '"Reuse": true'
215215
stdout '"Error":.*no matching versions'
216216
stdout '"TagPrefix": "sub/"'
@@ -221,7 +221,7 @@ stdout '"Hash": "fc3a09f3dc5cfe0d7a743ea18f1f5226e68b3777"'
221221

222222
# reuse go mod download vcstest/hello@nonexist
223223
! go mod download -reuse=hellononexist.json -x -json vcs-test.golang.org/git/hello.git@nonexist
224-
! stderr 'git fetch'
224+
! stderr 'git( .*)* fetch'
225225
stdout '"Reuse": true'
226226
stdout '"Version": "nonexist"'
227227
stdout '"Error":.*unknown revision nonexist'
@@ -231,7 +231,7 @@ stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
231231

232232
# reuse go mod download vcstest/hello@1234567890123456789012345678901234567890
233233
! go mod download -reuse=hellononhash.json -x -json vcs-test.golang.org/git/hello.git@1234567890123456789012345678901234567890
234-
! stderr 'git fetch'
234+
! stderr 'git( .*)* fetch'
235235
stdout '"Reuse": true'
236236
stdout '"Version": "1234567890123456789012345678901234567890"'
237237
stdout '"Error":.*unknown revision 1234567890123456789012345678901234567890'
@@ -241,7 +241,7 @@ stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
241241

242242
# reuse go mod download vcstest/[email protected]
243243
! go mod download -reuse=hellononpseudo.json -x -json vcs-test.golang.org/git/[email protected]
244-
! stderr 'git fetch'
244+
! stderr 'git( .*)* fetch'
245245
stdout '"Reuse": true'
246246
stdout '"Version": "v0.0.0-20220101120101-123456789abc"'
247247
stdout '"Error":.*unknown revision 123456789abc'
@@ -251,7 +251,7 @@ stdout '"RepoSum": "r1:c0/9JCZ25lxoBiK3[+]3BhACU4giH49flcJmBynJ[+]Jvmc="'
251251

252252
# reuse go mod download vcstest/tagtests result
253253
go mod download -reuse=tagtests.json -x -json vcs-test.golang.org/git/tagtests.git@latest
254-
! stderr 'git fetch'
254+
! stderr 'git( .*)* fetch'
255255
stdout '"Reuse": true'
256256
stdout '"Version": "v0.2.2"'
257257
stdout '"Query": "latest"'
@@ -265,7 +265,7 @@ stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
265265

266266
# reuse go mod download vcstest/[email protected] result
267267
go mod download -reuse=tagtestsv022.json -x -json vcs-test.golang.org/git/[email protected]
268-
! stderr 'git fetch'
268+
! stderr 'git( .*)* fetch'
269269
stdout '"Reuse": true'
270270
stdout '"Version": "v0.2.2"'
271271
! stdout '"Query":'
@@ -279,7 +279,7 @@ stdout '"Hash": "59356c8cd18c5fe9a598167d98a6843e52d57952"'
279279

280280
# reuse go mod download vcstest/tagtests@master result
281281
go mod download -reuse=tagtestsmaster.json -x -json vcs-test.golang.org/git/tagtests.git@master
282-
! stderr 'git fetch'
282+
! stderr 'git( .*)* fetch'
283283
stdout '"Reuse": true'
284284
stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"'
285285
stdout '"Query": "master"'
@@ -293,7 +293,7 @@ stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
293293

294294
# reuse go mod download vcstest/tagtests@master result again with all.json
295295
go mod download -reuse=all.json -x -json vcs-test.golang.org/git/tagtests.git@master
296-
! stderr 'git fetch'
296+
! stderr 'git( .*)* fetch'
297297
stdout '"Reuse": true'
298298
stdout '"Version": "v0.2.3-0.20190509225625-c7818c24fa2f"'
299299
stdout '"Query": "master"'
@@ -307,7 +307,7 @@ stdout '"Hash": "c7818c24fa2f3f714c67d0a6d3e411c85a518d1f"'
307307

308308
# go mod download vcstest/prefixtagtests result with json
309309
go mod download -reuse=prefixtagtests.json -x -json vcs-test.golang.org/git/prefixtagtests.git/sub@latest
310-
! stderr 'git fetch'
310+
! stderr 'git( .*)* fetch'
311311
stdout '"Version": "v0.0.10"'
312312
stdout '"Query": "latest"'
313313
stdout '"VCS": "git"'
@@ -321,15 +321,15 @@ stdout '"Hash": "2b7c4692e12c109263cab51b416fcc835ddd7eae"'
321321

322322
# reuse the bulk results with all.json
323323
! go mod download -reuse=all.json -json vcs-test.golang.org/git/hello.git@latest vcs-test.golang.org/git/hello.git/v9@latest vcs-test.golang.org/git/hello.git/sub/v9@latest vcs-test.golang.org/git/tagtests.git@latest vcs-test.golang.org/git/[email protected] vcs-test.golang.org/git/tagtests.git@master
324-
! stderr 'git fetch'
324+
! stderr 'git( .*)* fetch'
325325
stdout '"Reuse": true'
326326
! stdout '"(Dir|Info|GoMod|Zip)"'
327327

328328
# reuse attempt with stale hash should reinvoke git, not report reuse
329329
cp tagtestsv022.json tagtestsv022badhash.json
330330
replace '57952' '56952XXX' tagtestsv022badhash.json
331331
go mod download -reuse=tagtestsv022badhash.json -x -json vcs-test.golang.org/git/[email protected]
332-
stderr 'git fetch'
332+
stderr 'git( .*)* fetch'
333333
! stdout '"Reuse": true'
334334
stdout '"Version": "v0.2.2"'
335335
! stdout '"Query"'

0 commit comments

Comments
 (0)