Skip to content

Commit 2bc79cd

Browse files
committed
Don't use packages.Load's underscore paths
When packages.Load can't find a module path, it fabricates one out of the current absolute path. We should not use that when it happens.
1 parent 11e1b13 commit 2bc79cd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cmd/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ func findCurrentRepo() (string, error) {
8080
Mode: packages.NeedName, // name gives us path as well
8181
}
8282
pkgs, err := packages.Load(pkgCfg, ".")
83-
if err == nil && len(pkgs) > 0 {
83+
// NB(directxman12): when go modules are off and we're outside GOPATH and
84+
// we don't otherwise have a good guess packages.Load will fabricate a path
85+
// that consists of `_/absolute/path/to/current/directory`. We shouldn't
86+
// use that when it happens.
87+
if err == nil && len(pkgs) > 0 && len(pkgs[0].PkgPath) > 0 && pkgs[0].PkgPath[0] != '_' {
8488
return pkgs[0].PkgPath, nil
8589
}
8690

0 commit comments

Comments
 (0)