// in module-aware mode (as opposed to GOPATH mode).
// It is equal to modload.Enabled, but not all packages can import modload.
ModulesEnabled bool
+
+ // GoModInGOPATH records whether we've found a go.mod in GOPATH/src
+ // in GO111MODULE=auto mode. In that case, we don't use modules
+ // but people might expect us to, so 'go get' warns.
+ GoModInGOPATH string
)
func init() {
// Should not happen: main.go should install the separate module-enabled get code.
base.Fatalf("go get: modules not implemented")
}
+ if cfg.GoModInGOPATH != "" {
+ // Warn about not using modules with GO111MODULE=auto when go.mod exists.
+ // To silence the warning, users can set GO111MODULE=off.
+ fmt.Fprintf(os.Stderr, "go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;\n\tignoring %s;\n\tsee 'go help modules'\n", base.ShortPath(cfg.GoModInGOPATH))
+ }
work.BuildInit()
} else {
if inGOPATH && !MustUseModules {
// No automatic enabling in GOPATH.
+ if root, _ := FindModuleRoot(cwd, "", false); root != "" {
+ cfg.GoModInGOPATH = filepath.Join(root, "go.mod")
+ }
return
}
root, _ := FindModuleRoot(cwd, "", MustUseModules)
--- /dev/null
+# go get in GO111MODULE=auto should warn when not using modules and go.mod exists
+
+env GO111MODULE=auto
+mkdir z
+cd z
+! go get # fails because no code in directory, not the warning
+stderr 'go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;\n\tignoring ..[/\\]go.mod;\n\tsee ''go help modules'''
+
+-- go.mod --
+module x