aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modcmd/tidy.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2019-03-28 13:18:37 -0400
committerBryan C. Mills <bcmills@google.com>2019-04-19 21:16:38 +0000
commita1c481d85139f77ab27210526f9dfa2f3b375ef9 (patch)
tree0365486227257c37aa1b6736c3a5f3f6a6cf36be /src/cmd/go/internal/modcmd/tidy.go
parent9f9e17a82fd7afa622424f51e458bb383cb952ce (diff)
downloadgo-a1c481d85139f77ab27210526f9dfa2f3b375ef9.tar.gz
go-a1c481d85139f77ab27210526f9dfa2f3b375ef9.zip
cmd/go: only add a 'go' directive on 'go mod tidy' or when a conversion occurs
If the go.mod file exists and is empty, we initialize it from any of various formats supported by legacy dependency-management tools. We also initialize the 'go' directive at that point: we know that the go.mod file is incomplete, because it does not reflect the information in the legacy configuration file, and since we know that the go.mod file is incomplete, we should complete it with as much information as we have — including the version of the language currently in use. However, if there is no legacy configuration file present, then we cannot infer that the go.mod file is incomplete: it may correctly specify a module without external dependencies. In that case, we should not initialize the 'go' directive either: the user will not be expecting unnecessary edits to the go.mod file, and we generally do not make unnecessary-but-helpful edits unless 'go mod tidy' is invoked explicitly. Fixes #30790 Fixes #31100 Change-Id: I05a7872bce54a917c10d910cd9a616cab52e2730 Reviewed-on: https://go-review.googlesource.com/c/go/+/169877 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modcmd/tidy.go')
-rw-r--r--src/cmd/go/internal/modcmd/tidy.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modcmd/tidy.go b/src/cmd/go/internal/modcmd/tidy.go
index 789e936608..8c68ec51d8 100644
--- a/src/cmd/go/internal/modcmd/tidy.go
+++ b/src/cmd/go/internal/modcmd/tidy.go
@@ -64,6 +64,7 @@ func runTidy(cmd *base.Command, args []string) {
}
}
modload.SetBuildList(keep)
+ modload.AddGoStmt()
modTidyGoSum() // updates memory copy; WriteGoMod on next line flushes it out
modload.WriteGoMod()
}