From: Constantin Konstantinidis Date: Sat, 5 Jun 2021 05:48:30 +0000 (+0200) Subject: [release-branch.go1.16] cmd/go: remove hint when no module is suggested X-Git-Tag: go1.16.7~4 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4c62fd36776c03547f7a9f8dc67c8dac8e987851;p=gostls13.git [release-branch.go1.16] cmd/go: remove hint when no module is suggested Updates #46528 Fixes #46551 Change-Id: I2453d321ece878ea7823865758aa4a16b3ed7fe8 Reviewed-on: https://go-review.googlesource.com/c/go/+/325430 Reviewed-by: Bryan C. Mills Run-TryBot: Bryan C. Mills Trust: Heschi Kreinick Trust: Dmitri Shuralyov TryBot-Result: Go Bot (cherry picked from commit e552a6d31270c86064632af1d092e0db5a930250) Reviewed-on: https://go-review.googlesource.com/c/go/+/334371 Trust: Bryan C. Mills Reviewed-by: Jay Conrod Reviewed-by: Michael Matloob --- diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go index 995641c9f1..eda0568f07 100644 --- a/src/cmd/go/internal/modload/import.go +++ b/src/cmd/go/internal/modload/import.go @@ -160,11 +160,13 @@ func (e *ImportMissingSumError) Error() string { // Importing package is unknown, or the missing package was named on the // command line. Recommend 'go mod download' for the modules that could // provide the package, since that shouldn't change go.mod. - args := make([]string, len(e.mods)) - for i, mod := range e.mods { - args[i] = mod.Path + if len(e.mods) > 0 { + args := make([]string, len(e.mods)) + for i, mod := range e.mods { + args[i] = mod.Path + } + hint = fmt.Sprintf("; to add:\n\tgo mod download %s", strings.Join(args, " ")) } - hint = fmt.Sprintf("; to add:\n\tgo mod download %s", strings.Join(args, " ")) } else { // Importing package is known (common case). Recommend 'go get' on the // current version of the importing package. diff --git a/src/cmd/go/testdata/script/mod_install_hint.txt b/src/cmd/go/testdata/script/mod_install_hint.txt new file mode 100644 index 0000000000..ab02840eb8 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_install_hint.txt @@ -0,0 +1,5 @@ +# Module is replaced but not required. No hint appears as no module is suggested. +go mod init m +go mod edit -replace=github.com/notrequired@v0.5.0=github.com/doesnotexist@v0.5.0 +! go install github.com/notrequired +! stderr 'to add it:' \ No newline at end of file