Skip to content

Commit b15afa6

Browse files
committed
Only add explicit -mod=vendor if needed
-mod=vendor is not needed if it's already set in GOFLAGS. So lets not set it unless it's needed. This is an issue for commands such as `go test` and `go vet` ( see: golang/go#32471 ). This avois such an issue.
1 parent fcdbd12 commit b15afa6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

internal/util/projutil/exec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (opts GoCmdOptions) getGeneralArgsWithCmd(cmd string) ([]string, error) {
124124
}
125125
// Does the first "go" subcommand accept -mod=vendor?
126126
_, ok := validVendorCmds[bargs[0]]
127-
if err == nil && info.IsDir() && ok {
127+
if err == nil && info.IsDir() && ok && needsModVendor() {
128128
bargs = append(bargs, "-mod=vendor")
129129
}
130130
}
@@ -135,6 +135,10 @@ func (opts GoCmdOptions) getGeneralArgsWithCmd(cmd string) ([]string, error) {
135135
return bargs, nil
136136
}
137137

138+
func needsModVendor() bool {
139+
return !strings.Contains(os.Getenv("GOFLAGS"), "-mod=vendor")
140+
}
141+
138142
func (opts GoCmdOptions) setCmdFields(c *exec.Cmd) {
139143
c.Env = append(c.Env, os.Environ()...)
140144
if len(opts.Env) != 0 {

0 commit comments

Comments
 (0)