Skip to content

Commit e79f590

Browse files
committed
Go: Fix checks for dep and glide not working correctly
1 parent ec90282 commit e79f590

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

go/extractor/project/project.go

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,35 @@ func getBuildRoots(emitDiagnostics bool) (goWorkspaces []GoWorkspace, totalModul
282282

283283
// If there are no `go.mod` files at all, create one in line with https://go.dev/blog/migrating-to-go-modules
284284
if totalModuleFiles == 0 {
285+
// Check for other, legacy package managers
286+
if util.FileExists("Gopkg.toml") {
287+
if emitDiagnostics {
288+
diagnostics.EmitGopkgTomlFound()
289+
}
290+
log.Println("Found Gopkg.toml, using dep instead of go get")
291+
goWorkspaces = []GoWorkspace{{
292+
BaseDir: ".",
293+
DepMode: Dep,
294+
ModMode: ModUnset,
295+
}}
296+
totalModuleFiles = 0
297+
return
298+
}
299+
300+
if util.FileExists("glide.yaml") {
301+
if emitDiagnostics {
302+
diagnostics.EmitGlideYamlFound()
303+
}
304+
log.Println("Found glide.yaml, using Glide instead of go get")
305+
goWorkspaces = []GoWorkspace{{
306+
BaseDir: ".",
307+
DepMode: Glide,
308+
ModMode: ModUnset,
309+
}}
310+
totalModuleFiles = 0
311+
return
312+
}
313+
285314
// If we have no `go.mod` files, then the project appears to be a legacy project without
286315
// a `go.mod` file. Check that there are actually Go source files before initializing a module
287316
// so that we correctly fail the extraction later.
@@ -372,34 +401,8 @@ func GetWorkspaceInfo(emitDiagnostics bool) []GoWorkspace {
372401
}
373402

374403
goWorkspaces, totalModuleFiles := getBuildRoots(emitDiagnostics)
375-
if totalModuleFiles > 0 {
376-
log.Printf("Found %d go.mod file(s): enabling go modules.\n", totalModuleFiles)
377-
return goWorkspaces
378-
}
379-
380-
if util.FileExists("Gopkg.toml") {
381-
if emitDiagnostics {
382-
diagnostics.EmitGopkgTomlFound()
383-
}
384-
log.Println("Found Gopkg.toml, using dep instead of go get")
385-
return []GoWorkspace{{
386-
BaseDir: ".",
387-
DepMode: Dep,
388-
ModMode: ModUnset,
389-
}}
390-
}
404+
log.Printf("Found %d go.mod file(s).\n", totalModuleFiles)
391405

392-
if util.FileExists("glide.yaml") {
393-
if emitDiagnostics {
394-
diagnostics.EmitGlideYamlFound()
395-
}
396-
log.Println("Found glide.yaml, using Glide instead of go get")
397-
return []GoWorkspace{{
398-
BaseDir: ".",
399-
DepMode: Glide,
400-
ModMode: ModUnset,
401-
}}
402-
}
403406
return goWorkspaces
404407
}
405408

0 commit comments

Comments
 (0)