From c8c3c29daa74f2d3e1a26f2e289ad3d2b9ba20dd Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Thu, 22 Oct 2020 18:26:14 -0400 Subject: [PATCH] cmd/go: don't import requirements into existing go.mod files Previously, if a go.mod file was present, and it only contained a module directive, any module-aware command would attempt to import requirements from a vendor configuration file like Gopkg.lock. This CL removes that functionality. It was undocumented and untested, and it can cause problems with -mod=readonly. It should never come up for go.mod files created with 'go mod init', since they have a "go" directive. For #40278 Change-Id: I64c0d67d204560aa5c775d29553883d094fd3b72 Reviewed-on: https://go-review.googlesource.com/c/go/+/264620 Trust: Jay Conrod Run-TryBot: Bryan C. Mills Reviewed-by: Bryan C. Mills TryBot-Result: Go Bot --- src/cmd/go/internal/modload/init.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index 1fcc53735c4..9baaf411249 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -396,12 +396,6 @@ func InitMod(ctx context.Context) { base.Fatalf("go: no module declaration in go.mod.\n\tRun 'go mod edit -module=example.com/mod' to specify the module path.") } - if len(f.Syntax.Stmt) == 1 && f.Module != nil { - // Entire file is just a module statement. - // Populate require if possible. - legacyModInit() - } - if err := checkModulePathLax(f.Module.Mod.Path); err != nil { base.Fatalf("go: %v", err) } @@ -605,10 +599,6 @@ func legacyModInit() { if err := modconv.ConvertLegacyConfig(modFile, cfg, data); err != nil { base.Fatalf("go: %v", err) } - if len(modFile.Syntax.Stmt) == 1 { - // Add comment to avoid re-converting every time it runs. - modFile.AddComment("// go: no requirements found in " + name) - } return } }