Skip to content

Commit

Permalink
[release-branch.go1.16] cmd/go: remove hint when no module is suggested
Browse files Browse the repository at this point in the history
Updates #46528
Fixes #46551

Change-Id: I2453d321ece878ea7823865758aa4a16b3ed7fe8
Reviewed-on: https://go-review.googlesource.com/c/go/+/325430
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Trust: Heschi Kreinick <heschi@google.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
(cherry picked from commit e552a6d)
Reviewed-on: https://go-review.googlesource.com/c/go/+/334371
Trust: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
  • Loading branch information
iwdgo authored and cagedmantis committed Aug 2, 2021
1 parent 8b6ae9b commit 4c62fd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/cmd/go/internal/modload/import.go
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions 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:'

0 comments on commit 4c62fd3

Please sign in to comment.