diff options
author | Bryan C. Mills <bcmills@google.com> | 2023-06-01 23:42:48 -0400 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-06-02 22:42:42 +0000 |
commit | c292a74c389aed9cab01d435a8f8cb4bfb087544 (patch) | |
tree | f268c438f6c42fc3ecb09b8f00f6f32ef3d877c2 /src/cmd/go/internal/modload/load.go | |
parent | 6260049fa2973dea717c748e0609c4143cfd70eb (diff) | |
download | go-c292a74c389aed9cab01d435a8f8cb4bfb087544.tar.gz go-c292a74c389aed9cab01d435a8f8cb4bfb087544.zip |
cmd/go: adjust conditions in which toolchain lines are written
'go mod tidy -go=1.20' should tidy as Go 1.20 did, without writing a
toolchain line implicitly. (We don't need it to stabilize toolchain
version switching anyway: because Go 1.20 predates toolchain
switching, any toolchain that supports switching toolchains also
supports Go 1.20 modules directly.)
For #57001.
Change-Id: I415abac75d8d6de9f8ed470aab0d1ed4c225b08d
Reviewed-on: https://go-review.googlesource.com/c/go/+/499987
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index c597d53dde..a96ce0283d 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -379,6 +379,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma search.WarnUnmatched(matches) } + tidyWroteGo := false if opts.Tidy { if cfg.BuildV { mg, _ := ld.requirements.Graph(ctx) @@ -422,6 +423,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma } } modFile.AddGoStmt(ld.GoVersion) + tidyWroteGo = true } if !ExplicitWriteGoMod { @@ -453,7 +455,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma sort.Strings(loadedPackages) if !ExplicitWriteGoMod && opts.ResolveMissingImports { - if err := commitRequirements(ctx, WriteOpts{}); err != nil { + if err := commitRequirements(ctx, WriteOpts{TidyWroteGo: tidyWroteGo}); err != nil { base.Fatal(err) } } |