diff --git a/internal/gps/_testdata/src/disallow/.m1p/a.go b/internal/gps/_testdata/src/disallow/.m1p/a.go index 6a88c12022..a5fc8c2e57 100644 --- a/internal/gps/_testdata/src/disallow/.m1p/a.go +++ b/internal/gps/_testdata/src/disallow/.m1p/a.go @@ -7,7 +7,7 @@ package m1p import ( "sort" - "github.com/golang/dep/gps" + "github.com/golang/dep/internal/gps" ) var ( diff --git a/internal/gps/_testdata/src/dotgodir/.go/dot.go b/internal/gps/_testdata/src/dotgodir/.go/dot.go new file mode 100644 index 0000000000..75d2fcf624 --- /dev/null +++ b/internal/gps/_testdata/src/dotgodir/.go/dot.go @@ -0,0 +1,3 @@ +package dot + +// nothing to see here diff --git a/internal/gps/pkgtree/pkgtree.go b/internal/gps/pkgtree/pkgtree.go index a6b452764d..1b2e94f135 100644 --- a/internal/gps/pkgtree/pkgtree.go +++ b/internal/gps/pkgtree/pkgtree.go @@ -28,6 +28,15 @@ type Package struct { TestImports []string // Imports from all go test files (in go/build parlance: both TestImports and XTestImports) } +// svnRoots is a set of directories we should not descend into in ListPackages when +// searching for Go packages +var svnRoots = map[string]struct{}{ + ".git": struct{}{}, + ".bzr": struct{}{}, + ".svn": struct{}{}, + ".hg": struct{}{}, +} + // ListPackages reports Go package information about all directories in the tree // at or below the provided fileRoot. // @@ -78,10 +87,13 @@ func ListPackages(fileRoot, importRoot string) (PackageTree, error) { case "vendor", "Godeps": return filepath.SkipDir } - // We do skip dot-dirs, though, because it's such a ubiquitous standard - // that they not be visited by normal commands, and because things get - // really weird if we don't. - if strings.HasPrefix(fi.Name(), ".") { + + // Skip dirs that are known to be VCS roots. + // + // Note that there are some pathological edge cases this doesn't cover, + // such as a user using Git for version control, but having a package + // named "svn" in a directory named ".svn". + if _, ok := svnRoots[fi.Name()]; ok { return filepath.SkipDir } diff --git a/internal/gps/pkgtree/pkgtree_test.go b/internal/gps/pkgtree/pkgtree_test.go index 092782c0d8..baf9277b40 100644 --- a/internal/gps/pkgtree/pkgtree_test.go +++ b/internal/gps/pkgtree/pkgtree_test.go @@ -1073,20 +1073,18 @@ func TestListPackages(t *testing.T) { }, }, }, - // disallow/.m1p is ignored by listPackages...for now. Kept - // here commented because this might change again... - //"disallow/.m1p": { - //P: Package{ - //ImportPath: "disallow/.m1p", - //CommentPath: "", - //Name: "m1p", - //Imports: []string{ - //"github.com/golang/dep/internal/gps", - //"os", - //"sort", - //}, - //}, - //}, + "disallow/.m1p": { + P: Package{ + ImportPath: "disallow/.m1p", + CommentPath: "", + Name: "m1p", + Imports: []string{ + "github.com/golang/dep/internal/gps", + "os", + "sort", + }, + }, + }, "disallow/testdata": { P: Package{ ImportPath: "disallow/testdata", @@ -1292,6 +1290,13 @@ func TestListPackages(t *testing.T) { Imports: []string{}, }, }, + "dotgodir/.go": { + P: Package{ + ImportPath: "dotgodir/.go", + Name: "dot", + Imports: []string{}, + }, + }, "dotgodir/foo.go": { P: Package{ ImportPath: "dotgodir/foo.go",