Skip to content

Commit

Permalink
Merge pull request #970 from go-wyvern/look_gop_go_mod
Browse files Browse the repository at this point in the history
look for enclosing gop.mod and go.mod
  • Loading branch information
xushiwei authored Nov 29, 2021
2 parents 2d815ae + 6db72ed commit 72af8d8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions cmd/internal/modload/modload.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ func findModuleRoot(dir string) (root string) {
}
dir = filepath.Clean(dir)

// Look for enclosing gop.mod.
// Look for enclosing gop.mod or go.mod.
for {
if fi, err := os.Stat(filepath.Join(dir, "gop.mod")); err == nil && !fi.IsDir() {
return dir
}
if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !fi.IsDir() {
return dir
}
d := filepath.Dir(dir)
if d == dir {
break
Expand Down Expand Up @@ -256,20 +259,18 @@ func fixGoVersion(fixed *bool) gomodfile.VersionFixer {
// As a side-effect, LoadModFile may change cfg.BuildMod to "vendor" if
// -mod wasn't set explicitly and automatic vendoring should be enabled.
func LoadModFile() {
if !HasModRoot() {
// If gop.mod does not exist, then modroot does not exist,
// and if go.mod exists in the current directory,
// then a copy of go.mod will be synchronized to gop.mod
cwd := getcwd()
gomod := filepath.Join(cwd, "go.mod")
Init()
// If gop.mod does not exist, then modroot does not exist,
// and if go.mod exists then a copy of go.mod will be synchronized to gop.mod
gopmod := GopModFilePath()
gomod := GoModFilePath()
if _, err := os.Stat(gopmod); os.IsNotExist(err) {
if _, err := os.Stat(gomod); err == nil {
modRoot = cwd
SyncGopMod()
}
return
}

gopmod := GopModFilePath()
data, err := modfetch.Read(gopmod)
if err != nil {
log.Fatalf("gop: %v", err)
Expand Down

0 comments on commit 72af8d8

Please sign in to comment.