Skip to content

Commit

Permalink
cmd/go: remove hint when no module is suggested
Browse files Browse the repository at this point in the history
Fixes #46528

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>
  • Loading branch information
iwdgo authored and Bryan C. Mills committed Jun 11, 2021
1 parent 16b5d76 commit e552a6d
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
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,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
Original file line number Diff line number Diff line change
@@ -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 e552a6d

Please sign in to comment.