Skip to content

Commit 3ab825d

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modget: warn about unmatched packages exactly once
Due to an inverted condition, we were emitting a "matched no packages" warning twice in some cases and not at all in others. For #41315 Change-Id: I472cd2d4f75811c8734852f2bdd7346f4c612816 Reviewed-on: https://go-review.googlesource.com/c/go/+/254819 Trust: Bryan C. Mills <[email protected]> Trust: Michael Matloob <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent de0957d commit 3ab825d

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/cmd/go/internal/modget/get.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,12 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
609609
}
610610
prevBuildList = buildList
611611
}
612-
if !*getD {
613-
// Only print warnings after the last iteration,
614-
// and only if we aren't going to build.
612+
if *getD {
613+
// Only print warnings after the last iteration, and only if we aren't going
614+
// to build (to avoid doubled warnings).
615+
//
616+
// Only local patterns in the main module, such as './...', can be unmatched.
617+
// (See the mod_get_nopkgs test for more detail.)
615618
search.WarnUnmatched(matches)
616619
}
617620

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
cd subdir
2+
3+
# 'go get' on empty patterns that are necessarily local to the module
4+
# should warn that the patterns are empty, exactly once.
5+
6+
go get ./...
7+
stderr -count=1 'matched no packages'
8+
9+
go get -d ./...
10+
stderr -count=1 'matched no packages'
11+
12+
# 'go get' on patterns that could conceivably match nested modules
13+
# should report a module resolution error.
14+
15+
go get -d example.net/emptysubdir/... # control case
16+
17+
! go get -d example.net/emptysubdir/subdir/...
18+
! stderr 'matched no packages'
19+
stderr '^go get example\.net/emptysubdir/subdir/\.\.\.: module example\.net/emptysubdir/subdir: reading http://.*: 404 Not Found\n\tserver response: 404 page not found\n\z'
20+
21+
# It doesn't make sense to 'go get' a path in the standard library,
22+
# since the standard library necessarily can't have unresolved imports.
23+
#
24+
# TODO(#30241): Maybe that won't always be the case?
25+
#
26+
# For that case, we emit a "malformed module path" error message,
27+
# which isn't ideal either.
28+
29+
! go get -d builtin/... # in GOROOT/src, but contains no packages
30+
stderr '^go get builtin/...: malformed module path "builtin": missing dot in first path element$'
31+
32+
-- go.mod --
33+
module example.net/emptysubdir
34+
35+
go 1.16
36+
-- emptysubdir.go --
37+
// Package emptysubdir has a subdirectory containing no packages.
38+
package emptysubdir
39+
-- subdir/README.txt --
40+
This module intentionally does not contain any p

0 commit comments

Comments
 (0)