From f1dce319ffd9d3663f522141abfb9c1ec9d92e04 Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Thu, 5 Aug 2021 15:18:42 -0700 Subject: cmd/go: with -mod=vendor, don't panic if there are duplicate requirements In loadModFile with -mod=vendor, load the vendor list and use it to initialize the module graph before calling updateRoots. In updateLazyRoots with any mode other than "mod", return the original *Requirements if no roots needed to be upgraded, even if there are inconsistencies. This means 'go list -m -mod=readonly' and -mod=vendor may succeed if there are duplicate requirements or requirements on versions of the main module. Fixes #47565 Change-Id: I4640dffc4a7359367cc910da0d29e3538bfd1ca4 Reviewed-on: https://go-review.googlesource.com/c/go/+/340252 Trust: Jay Conrod Trust: Bryan C. Mills Reviewed-by: Bryan C. Mills --- .../script/mod_vendor_redundant_requirement.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/cmd/go/testdata/script/mod_vendor_redundant_requirement.txt (limited to 'src/cmd/go/testdata/script/mod_vendor_redundant_requirement.txt') diff --git a/src/cmd/go/testdata/script/mod_vendor_redundant_requirement.txt b/src/cmd/go/testdata/script/mod_vendor_redundant_requirement.txt new file mode 100644 index 0000000000..3f6f5c5276 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_vendor_redundant_requirement.txt @@ -0,0 +1,29 @@ +# 'go list -mod=vendor' should succeed even when go.mod contains redundant +# requirements. Verifies #47565. +go list -mod=vendor + +-- go.mod -- +module m + +go 1.17 + +require example.com/m v0.0.0 +require example.com/m v0.0.0 + +replace example.com/m v0.0.0 => ./m +-- m/go.mod -- +module example.com/m + +go 1.17 +-- m/m.go -- +package m +-- use.go -- +package use + +import _ "example.com/m" +-- vendor/example.com/m/m.go -- +package m +-- vendor/modules.txt -- +# example.com/m v0.0.0 => ./m +## explicit; go 1.17 +example.com/m -- cgit v1.2.3-54-g00ecf