aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modget/get.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-09-18 14:15:56 -0400
committerBryan C. Mills <bcmills@google.com>2020-09-22 18:00:04 +0000
commit095f66f662ac73e2aafbc369c59fc3870eb9b86f (patch)
tree745113c39cdafbc72f2eb04637c615240eab6dc7 /src/cmd/go/internal/modget/get.go
parentea42b771e9f0726b0e10278df0b5759b984e9cc3 (diff)
downloadgo-095f66f662ac73e2aafbc369c59fc3870eb9b86f.tar.gz
go-095f66f662ac73e2aafbc369c59fc3870eb9b86f.zip
cmd/go/internal/modget: if building packages, only update go.mod if the build succeeds
Fixes #41315 Change-Id: I5b18a0c2d1d72ff556a882e862b95133deb3ef98 Reviewed-on: https://go-review.googlesource.com/c/go/+/255970 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modget/get.go')
-rw-r--r--src/cmd/go/internal/modget/get.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go
index 7e573bacb7..f1cf8b17a8 100644
--- a/src/cmd/go/internal/modget/get.go
+++ b/src/cmd/go/internal/modget/get.go
@@ -588,6 +588,20 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
modload.LoadPackages(ctx, loadOpts, pkgPatterns...)
}
+ // If -d was specified, we're done after the module work.
+ // We've already downloaded modules by loading packages above.
+ // Otherwise, we need to build and install the packages matched by
+ // command line arguments. This may be a different set of packages,
+ // since we only build packages for the target platform.
+ // Note that 'go get -u' without arguments is equivalent to
+ // 'go get -u .', so we'll typically build the package in the current
+ // directory.
+ if !*getD && len(pkgPatterns) > 0 {
+ work.BuildInit()
+ pkgs := load.PackagesForBuild(ctx, pkgPatterns)
+ work.InstallPackages(ctx, pkgPatterns, pkgs)
+ }
+
// Everything succeeded. Update go.mod.
modload.AllowWriteGoMod()
modload.WriteGoMod()
@@ -600,21 +614,6 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
// contains information about direct dependencies that WriteGoMod uses.
// Refactor to avoid these kinds of global side effects.
reportRetractions(ctx)
-
- // If -d was specified, we're done after the module work.
- // We've already downloaded modules by loading packages above.
- // Otherwise, we need to build and install the packages matched by
- // command line arguments. This may be a different set of packages,
- // since we only build packages for the target platform.
- // Note that 'go get -u' without arguments is equivalent to
- // 'go get -u .', so we'll typically build the package in the current
- // directory.
- if *getD || len(pkgPatterns) == 0 {
- return
- }
- work.BuildInit()
- pkgs := load.PackagesForBuild(ctx, pkgPatterns)
- work.InstallPackages(ctx, pkgPatterns, pkgs)
}
// parseArgs parses command-line arguments and reports errors.