File tree 3 files changed +49
-0
lines changed 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ package modcmd
8
8
9
9
import (
10
10
"bufio"
11
+ "cmd/go/internal/cfg"
11
12
"os"
12
13
"sort"
13
14
@@ -33,6 +34,14 @@ func runGraph(cmd *base.Command, args []string) {
33
34
if len (args ) > 0 {
34
35
base .Fatalf ("go mod graph: graph takes no arguments" )
35
36
}
37
+ // Checks go mod expected behavior
38
+ if ! modload .Enabled () {
39
+ if cfg .Getenv ("GO111MODULE" ) == "off" {
40
+ base .Fatalf ("go: modules disabled by GO111MODULE=off; see 'go help modules'" )
41
+ } else {
42
+ base .Fatalf ("go: cannot find main module; see 'go help modules'" )
43
+ }
44
+ }
36
45
modload .LoadBuildList ()
37
46
38
47
reqs := modload .MinReqs ()
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package modcmd
6
6
7
7
import (
8
8
"bytes"
9
+ "cmd/go/internal/cfg"
9
10
"fmt"
10
11
"io/ioutil"
11
12
"os"
@@ -36,6 +37,14 @@ func runVerify(cmd *base.Command, args []string) {
36
37
// NOTE(rsc): Could take a module pattern.
37
38
base .Fatalf ("go mod verify: verify takes no arguments" )
38
39
}
40
+ // Checks go mod expected behavior
41
+ if ! modload .Enabled () {
42
+ if cfg .Getenv ("GO111MODULE" ) == "off" {
43
+ base .Fatalf ("go: modules disabled by GO111MODULE=off; see 'go help modules'" )
44
+ } else {
45
+ base .Fatalf ("go: cannot find main module; see 'go help modules'" )
46
+ }
47
+ }
39
48
ok := true
40
49
for _ , mod := range modload .LoadBuildList ()[1 :] {
41
50
ok = verifyMod (mod ) && ok
Original file line number Diff line number Diff line change
1
+ env GO111MODULE=off
2
+
3
+ # This script tests that running go mod with
4
+ # GO111MODULE=off when outside of GOPATH will fatal
5
+ # with an error message, even with some source code in the directory and a go.mod.
6
+ ! go mod init
7
+ stderr 'go mod init: modules disabled by GO111MODULE=off; see ''go help modules'''
8
+ ! go mod graph
9
+ stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules'''
10
+ ! go mod verify
11
+ stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules'''
12
+
13
+ # Same result in an empty directory
14
+ mkdir z
15
+ cd z
16
+ ! go mod init
17
+ stderr 'go mod init: modules disabled by GO111MODULE=off; see ''go help modules'''
18
+ ! go mod graph
19
+ stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules'''
20
+ ! go mod verify
21
+ stderr 'go: modules disabled by GO111MODULE=off; see ''go help modules'''
22
+
23
+ -- sample.go --
24
+ package sample
25
+
26
+ func main() {}
27
+
28
+ -- go.mod --
29
+ module sample
30
+
31
+ go 1.12
You can’t perform that action at this time.
0 commit comments