]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't import requirements into existing go.mod files
authorJay Conrod <jayconrod@google.com>
Thu, 22 Oct 2020 22:26:14 +0000 (18:26 -0400)
committerJay Conrod <jayconrod@google.com>
Fri, 23 Oct 2020 20:54:12 +0000 (20:54 +0000)
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 <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/go/internal/modload/init.go

index 1fcc53735c45ef463ed518a841b3b18fcd74e7d8..9baaf411249caa049716cfeb78ec7968c0ae4dae 100644 (file)
@@ -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
                }
        }