diff --git a/src/cmd/go/internal/modcmd/tidy.go b/src/cmd/go/internal/modcmd/tidy.go index 34ff86ff185..33ecd80bcb5 100644 --- a/src/cmd/go/internal/modcmd/tidy.go +++ b/src/cmd/go/internal/modcmd/tidy.go @@ -60,6 +60,7 @@ func runTidy(ctx context.Context, cmd *base.Command, args []string) { // request that their test dependencies be included. modload.ForceUseModules = true modload.RootMode = modload.NeedRoot + modload.DisallowWriteGoMod() // Suppress writing until we've tidied the file. modload.LoadPackages(ctx, modload.PackageOpts{ Tags: imports.AnyTags(), @@ -72,5 +73,7 @@ func runTidy(ctx context.Context, cmd *base.Command, args []string) { modload.TidyBuildList() modload.TrimGoSum() + + modload.AllowWriteGoMod() modload.WriteGoMod() }