diff options
author | Jay Conrod <jayconrod@google.com> | 2019-04-21 15:21:58 -0400 |
---|---|---|
committer | Jay Conrod <jayconrod@google.com> | 2019-04-30 22:20:57 +0000 |
commit | 65b89c3542fb3d36632e404f672b41f111b8b60a (patch) | |
tree | 803a9d73b058db0bc166c8b2d9bf1084ca9ed8ab /src/cmd/go/internal/modload/query.go | |
parent | 4d9dd3580624df413d65d83e467fcd6ad4a0168b (diff) | |
download | go-65b89c3542fb3d36632e404f672b41f111b8b60a.tar.gz go-65b89c3542fb3d36632e404f672b41f111b8b60a.zip |
cmd/go: make get -u upgrade only modules providing packages
Currently, 'go get -u' upgrades modules matching command line
arguments and any modules they transitively require. 'go get -u' with
no positional arguments upgrades all modules transitively required by
the main module. This usually adds a large number of indirect
requirements, which is surprising to users.
With this change, 'go get' will load packages specified by
its arguments using a similar process to other commands
('go build', etc). Only modules providing packages will be upgraded.
'go get -u' now upgrades modules providing packages transitively
imported by the command-line arguments. 'go get -u' without arguments
will only upgrade modules needed by the package in the current
directory.
'go get -m' will load all packages within a module. 'go get -m -u'
without arguments will upgrade modules needed by the main module. It
is equivalent to 'go get -u all'. Neither command will upgrade modules
that are required but not used.
Note that 'go get -m' and 'go get -d' both download modules in order
to load packages.
Fixes #26902
Change-Id: I2bad686b3ca8c9de985a81fb42b16a36bb4cc3ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/174099
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/query.go')
-rw-r--r-- | src/cmd/go/internal/modload/query.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go index 74847a2912..a195b76fa1 100644 --- a/src/cmd/go/internal/modload/query.go +++ b/src/cmd/go/internal/modload/query.go @@ -442,3 +442,13 @@ func (e *packageNotInModuleError) Error() string { } return fmt.Sprintf("module %s@%s%s found, but does not contain package %s", e.mod.Path, e.query, found, e.pattern) } + +// ModuleHasRootPackage returns whether module m contains a package m.Path. +func ModuleHasRootPackage(m module.Version) (bool, error) { + root, isLocal, err := fetch(m) + if err != nil { + return false, err + } + _, ok := dirInModule(m.Path, m.Path, root, isLocal) + return ok, nil +} |