aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modcmd/tidy.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/go/internal/modcmd/tidy.go')
-rw-r--r--src/cmd/go/internal/modcmd/tidy.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/cmd/go/internal/modcmd/tidy.go b/src/cmd/go/internal/modcmd/tidy.go
index 30df674ef6..fb43e33ec5 100644
--- a/src/cmd/go/internal/modcmd/tidy.go
+++ b/src/cmd/go/internal/modcmd/tidy.go
@@ -9,12 +9,13 @@ package modcmd
import (
"cmd/go/internal/base"
"cmd/go/internal/cfg"
+ "cmd/go/internal/imports"
"cmd/go/internal/modload"
"context"
)
var cmdTidy = &base.Command{
- UsageLine: "go mod tidy [-v]",
+ UsageLine: "go mod tidy [-e] [-v]",
Short: "add missing and remove unused modules",
Long: `
Tidy makes sure go.mod matches the source code in the module.
@@ -25,12 +26,18 @@ to go.sum and removes any unnecessary ones.
The -v flag causes tidy to print information about removed modules
to standard error.
+
+The -e flag causes tidy to attempt to proceed despite errors
+encountered while loading packages.
`,
+ Run: runTidy,
}
+var tidyE bool // if true, report errors but proceed anyway.
+
func init() {
- cmdTidy.Run = runTidy // break init cycle
cmdTidy.Flag.BoolVar(&cfg.BuildV, "v", false, "")
+ cmdTidy.Flag.BoolVar(&tidyE, "e", false, "")
base.AddModCommonFlags(&cmdTidy.Flag)
}
@@ -49,9 +56,16 @@ func runTidy(ctx context.Context, cmd *base.Command, args []string) {
// those packages. In order to make 'go test' reproducible for the packages
// that are in 'all' but outside of the main module, we must explicitly
// request that their test dependencies be included.
- modload.LoadTests = true
+ modload.ForceUseModules = true
+ modload.RootMode = modload.NeedRoot
+
+ modload.LoadPackages(ctx, modload.PackageOpts{
+ Tags: imports.AnyTags(),
+ ResolveMissingImports: true,
+ LoadTests: true,
+ AllowErrors: tidyE,
+ }, "all")
- modload.LoadALL(ctx)
modload.TidyBuildList()
modload.TrimGoSum()
modload.WriteGoMod()