Skip to content

Commit 6af821f

Browse files
committed
Allow dot-prefixed packages as valid import paths
Fixes golang#564
1 parent b86ad16 commit 6af821f

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

internal/gps/_testdata/src/disallow/.m1p/a.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package m1p
77
import (
88
"sort"
99

10-
"github.com/golang/dep/gps"
10+
"github.com/golang/dep/internal/gps"
1111
)
1212

1313
var (
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package dot
2+
3+
// nothing to see here

internal/gps/pkgtree/pkgtree.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ type Package struct {
2828
TestImports []string // Imports from all go test files (in go/build parlance: both TestImports and XTestImports)
2929
}
3030

31+
// svnRoots is a set of directories we should not descend into in ListPackages when
32+
// searching for Go packages
33+
var svnRoots = map[string]struct{}{
34+
".git": struct{}{},
35+
".bzr": struct{}{},
36+
".svn": struct{}{},
37+
".hg": struct{}{},
38+
}
39+
3140
// ListPackages reports Go package information about all directories in the tree
3241
// at or below the provided fileRoot.
3342
//
@@ -78,10 +87,13 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) {
7887
case "vendor", "Godeps":
7988
return filepath.SkipDir
8089
}
81-
// We do skip dot-dirs, though, because it's such a ubiquitous standard
82-
// that they not be visited by normal commands, and because things get
83-
// really weird if we don't.
84-
if strings.HasPrefix(fi.Name(), ".") {
90+
91+
// Skip dirs that are known to be VCS roots.
92+
//
93+
// Note that there are some pathological edge cases this doesn't cover,
94+
// such as a user using Git for version control, but having a package
95+
// named "svn" in a directory named ".svn".
96+
if _, ok := svnRoots[fi.Name()]; ok {
8597
return filepath.SkipDir
8698
}
8799

internal/gps/pkgtree/pkgtree_test.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,20 +1073,18 @@ func TestListPackages(t *testing.T) {
10731073
},
10741074
},
10751075
},
1076-
// disallow/.m1p is ignored by listPackages...for now. Kept
1077-
// here commented because this might change again...
1078-
//"disallow/.m1p": {
1079-
//P: Package{
1080-
//ImportPath: "disallow/.m1p",
1081-
//CommentPath: "",
1082-
//Name: "m1p",
1083-
//Imports: []string{
1084-
//"github.com/golang/dep/internal/gps",
1085-
//"os",
1086-
//"sort",
1087-
//},
1088-
//},
1089-
//},
1076+
"disallow/.m1p": {
1077+
P: Package{
1078+
ImportPath: "disallow/.m1p",
1079+
CommentPath: "",
1080+
Name: "m1p",
1081+
Imports: []string{
1082+
"github.com/golang/dep/internal/gps",
1083+
"os",
1084+
"sort",
1085+
},
1086+
},
1087+
},
10901088
"disallow/testdata": {
10911089
P: Package{
10921090
ImportPath: "disallow/testdata",
@@ -1292,6 +1290,13 @@ func TestListPackages(t *testing.T) {
12921290
Imports: []string{},
12931291
},
12941292
},
1293+
"dotgodir/.go": {
1294+
P: Package{
1295+
ImportPath: "dotgodir/.go",
1296+
Name: "dot",
1297+
Imports: []string{},
1298+
},
1299+
},
12951300
"dotgodir/foo.go": {
12961301
P: Package{
12971302
ImportPath: "dotgodir/foo.go",

0 commit comments

Comments
 (0)