Commit cb7d0efc authored by Russ Cox's avatar Russ Cox

cmd/go: fix go.mod corruption using -mod=vendor

If we're using -mod=vendor then we effectively load
a fake build list from vendor/modules.txt.
Do not write it back to go.mod.

Fixes #26704.

Change-Id: Ie79f2103dc16d0b7fe0c884e77ba726c7e04f2e4
Reviewed-on: https://go-review.googlesource.com/128899Reviewed-by: 's avatarBryan C. Mills <bcmills@google.com>
parent 7aa98557
......@@ -521,7 +521,10 @@ func MinReqs() mvs.Reqs {
// WriteGoMod writes the current build list back to go.mod.
func WriteGoMod() {
if !allowWriteGoMod {
// If we're using -mod=vendor we basically ignored
// go.mod, so definitely don't try to write back our
// incomplete view of the world.
if !allowWriteGoMod || cfg.BuildMod == "vendor" {
return
}
......
env GO111MODULE=on
# initial conditions: using sampler v1.3.0, not listed in go.mod.
go list -deps
stdout rsc.io/sampler
! grep 'rsc.io/sampler v1.3.0' go.mod
# update to v1.3.1, now indirect in go.mod.
go get rsc.io/sampler@v1.3.1
grep 'rsc.io/sampler v1.3.1 // indirect' go.mod
cp go.mod go.mod.good
# vendoring can but should not need to make changes.
go mod vendor
cmp go.mod go.mod.good
# go list -mod=vendor (or go build -mod=vendor) must not modify go.mod.
# golang.org/issue/26704
go list -mod=vendor
cmp go.mod go.mod.good
-- go.mod --
module m
-- x.go --
package x
import _ "rsc.io/quote"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment