diff options
author | Bryan C. Mills <bcmills@google.com> | 2018-11-08 10:29:40 -0500 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2018-11-29 18:57:53 +0000 |
commit | cdbd4d49d8b3595048ae63ac0f3891633470dfbe (patch) | |
tree | 5c022d3524572f5289af1d4b7070ec761eaf3a64 /src/cmd/go/internal/modload/search.go | |
parent | a2b4ac6cf29d31f1c927720712a25cda7bfbc682 (diff) | |
download | go-cdbd4d49d8b3595048ae63ac0f3891633470dfbe.tar.gz go-cdbd4d49d8b3595048ae63ac0f3891633470dfbe.zip |
cmd/go: enable module mode without a main module when GO111MODULE=on
This is as minimal a change as I could comfortably make to enable 'go
get' outside of a module for 1.12.
In general, commands invoked in module mode while outside of a module
operate as though they are in a module with an initially-empty go.mod
file. ('go env GOMOD' reports os.DevNull.)
Commands that operate on the current directory (such as 'go list' and
'go get -u' without arguments) fail: without a module definition, we
don't know the package path. Likewise, commands whose sole purpose is
to write files within the main module (such as 'go mod edit' and 'go
mod vendor') fail, since we don't know where to write their output.
Since the go.sum file for the main module is authoritative, we do not
check go.sum files when operating outside of a module. I plan to
revisit that when the tree opens for 1.13.
We may also want to revisit the behavior of 'go list': it would be
useful to be able to query individual packages (and dependencies of
those packages) within versioned modules, but today we only allow
versioned paths in conjunction with the '-m' flag.
Fixes #24250
RELNOTE=yes
Change-Id: I028c323ddea27693a92ad0aa4a6a55d5e3f43f2c
Reviewed-on: https://go-review.googlesource.com/c/148517
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/search.go')
-rw-r--r-- | src/cmd/go/internal/modload/search.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/search.go b/src/cmd/go/internal/modload/search.go index 24825cc35d..7d8852d01d 100644 --- a/src/cmd/go/internal/modload/search.go +++ b/src/cmd/go/internal/modload/search.go @@ -118,7 +118,10 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules [] } var root string if mod.Version == "" { - root = ModRoot + if !HasModRoot() { + continue // If there is no main module, we can't search in it. + } + root = ModRoot() } else { var err error root, _, err = fetch(mod) |