diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-05-14 16:53:06 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-05-25 13:18:26 +0000 |
commit | 8b462d75670dcd8b6a08cf9af225eb8e7628d412 (patch) | |
tree | 8c27c58384d324a7c19d6a041a364693ac5cf4b1 /src/cmd/go/internal/modcmd | |
parent | c89f1224a544cde464fcb86e78ebb0cc97eedba2 (diff) | |
download | go-git-8b462d75670dcd8b6a08cf9af225eb8e7628d412.tar.gz |
cmd/go: add a -compat flag to 'go mod tidy'
Fixes #46141
Change-Id: I9d4032e75252ade9eaa937389ea97ef3fb287499
Reviewed-on: https://go-review.googlesource.com/c/go/+/321071
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modcmd')
-rw-r--r-- | src/cmd/go/internal/modcmd/tidy.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modcmd/tidy.go b/src/cmd/go/internal/modcmd/tidy.go index 9af624028a..fe25507e94 100644 --- a/src/cmd/go/internal/modcmd/tidy.go +++ b/src/cmd/go/internal/modcmd/tidy.go @@ -19,7 +19,7 @@ import ( ) var cmdTidy = &base.Command{ - UsageLine: "go mod tidy [-e] [-v] [-go=version]", + UsageLine: "go mod tidy [-e] [-v] [-go=version] [-compat=version]", Short: "add missing and remove unused modules", Long: ` Tidy makes sure go.mod matches the source code in the module. @@ -40,20 +40,30 @@ are retained as explicit requirements in the go.mod file. (Go versions 1.17 and higher retain more requirements in order to support lazy module loading.) +The -compat flag preserves any additional checksums needed for the +'go' command from the indicated major Go release to successfully load +the module graph, and causes tidy to error out if that version of the +'go' command would load any imported package from a different module +version. By default, tidy acts as if the -compat flag were set to the +version prior to the one indicated by the 'go' directive in the go.mod +file. + See https://golang.org/ref/mod#go-mod-tidy for more about 'go mod tidy'. `, Run: runTidy, } var ( - tidyE bool // if true, report errors but proceed anyway. - tidyGo goVersionFlag // go version to write to the tidied go.mod file (toggles lazy loading) + tidyE bool // if true, report errors but proceed anyway. + tidyGo goVersionFlag // go version to write to the tidied go.mod file (toggles lazy loading) + tidyCompat goVersionFlag // go version for which the tidied go.mod and go.sum files should be “compatible” ) func init() { cmdTidy.Flag.BoolVar(&cfg.BuildV, "v", false, "") cmdTidy.Flag.BoolVar(&tidyE, "e", false, "") cmdTidy.Flag.Var(&tidyGo, "go", "") + cmdTidy.Flag.Var(&tidyCompat, "compat", "") base.AddModCommonFlags(&cmdTidy.Flag) } @@ -105,6 +115,7 @@ func runTidy(ctx context.Context, cmd *base.Command, args []string) { GoVersion: tidyGo.String(), Tags: imports.AnyTags(), Tidy: true, + TidyCompatibleVersion: tidyCompat.String(), VendorModulesInGOROOTSrc: true, ResolveMissingImports: true, LoadTests: true, |