From c98026c104dece6cf9aa6cf3f651dd16a0156cf2 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 14 Apr 2021 10:16:51 -0400 Subject: [PATCH] cmd/go/internal/modload: fix truncated error message from goModDirtyError The 'go mod tidy' hint was truncated due to a typo in CL 293689, and that particular case was not covered by any existing test. Updates #36460 Updates #40775 Change-Id: Ib6fa872a9dfdafc4e9a112e8add2ff5aecd2dbd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/310089 Trust: Bryan C. Mills Run-TryBot: Bryan C. Mills Reviewed-by: David Chase TryBot-Result: Go Bot --- src/cmd/go/internal/modload/init.go | 2 +- .../go/testdata/script/mod_require_exclude.txt | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index 777b63841fd..120afef4ff4 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -354,7 +354,7 @@ func (goModDirtyError) Error() string { return fmt.Sprintf("updates to go.mod needed, disabled by -mod=%v; to update it:\n\tgo mod tidy", cfg.BuildMod) } if cfg.BuildModReason != "" { - return fmt.Sprintf("updates to go.mod needed, disabled by -mod=%s\n\t(%s)\n\tto update it:\n\t", cfg.BuildMod, cfg.BuildModReason) + return fmt.Sprintf("updates to go.mod needed, disabled by -mod=%s\n\t(%s)\n\tto update it:\n\tgo mod tidy", cfg.BuildMod, cfg.BuildModReason) } return "updates to go.mod needed; to update it:\n\tgo mod tidy" } diff --git a/src/cmd/go/testdata/script/mod_require_exclude.txt b/src/cmd/go/testdata/script/mod_require_exclude.txt index 5b6143da42f..0946dbf0bb3 100644 --- a/src/cmd/go/testdata/script/mod_require_exclude.txt +++ b/src/cmd/go/testdata/script/mod_require_exclude.txt @@ -17,6 +17,17 @@ stderr '^go: updates to go.mod needed, disabled by -mod=vendor; to update it:\n\ ! stdout '^rsc.io/sampler v1.99.99' cmp go.mod go.mod.orig +# The failure message should be clear when -mod=vendor is implicit. + +go mod edit -go=1.14 +! go list -m rsc.io/sampler +stderr '^go: ignoring requirement on excluded version rsc.io/sampler v1\.99\.99$' +stderr '^go: updates to go.mod needed, disabled by -mod=vendor\n\t\(Go version in go.mod is at least 1.14 and vendor directory exists\.\)\n\tto update it:\n\tgo mod tidy$' +! stdout '^rsc.io/sampler v1.99.99' +go mod edit -go=1.13 +cmp go.mod go.mod.orig + + # With the selected version excluded, commands that load only modules should # drop the excluded module. @@ -58,7 +69,11 @@ module x go 1.13 exclude rsc.io/sampler v1.99.99 + require rsc.io/sampler v1.99.99 +-- vendor/modules.txt -- +# rsc.io/sampler v1.99.99 +## explicit -- go.moddrop -- module x