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..bb51d69f9a --- /dev/null +++ b/internal/gps/_testdata/src/dotgodir/.go/dot.go @@ -0,0 +1,7 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package dot + +// nothing to see here diff --git a/internal/gps/_testdata/src/disallow/.m1p/a.go b/internal/gps/_testdata/src/dotgodir/.m1p/a.go similarity index 86% rename from internal/gps/_testdata/src/disallow/.m1p/a.go rename to internal/gps/_testdata/src/dotgodir/.m1p/a.go index 6a88c12022..a5fc8c2e57 100644 --- a/internal/gps/_testdata/src/disallow/.m1p/a.go +++ b/internal/gps/_testdata/src/dotgodir/.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/disallow/.m1p/b.go b/internal/gps/_testdata/src/dotgodir/.m1p/b.go similarity index 100% rename from internal/gps/_testdata/src/disallow/.m1p/b.go rename to internal/gps/_testdata/src/dotgodir/.m1p/b.go diff --git a/internal/gps/pkgtree/pkgtree.go b/internal/gps/pkgtree/pkgtree.go index a6b452764d..271329059d 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) } +// vcsRoots is a set of directories we should not descend into in ListPackages when +// searching for Go packages +var vcsRoots = 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 := vcsRoots[fi.Name()]; ok { return filepath.SkipDir } diff --git a/internal/gps/pkgtree/pkgtree_test.go b/internal/gps/pkgtree/pkgtree_test.go index 092782c0d8..f042c2e312 100644 --- a/internal/gps/pkgtree/pkgtree_test.go +++ b/internal/gps/pkgtree/pkgtree_test.go @@ -1073,20 +1073,6 @@ 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/testdata": { P: Package{ ImportPath: "disallow/testdata", @@ -1280,7 +1266,7 @@ func TestListPackages(t *testing.T) { }, }, }, - "skip directories starting with '.'": { + "does not skip directories starting with '.'": { fileRoot: j("dotgodir"), importRoot: "dotgodir", out: PackageTree{ @@ -1292,6 +1278,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", @@ -1299,6 +1292,18 @@ func TestListPackages(t *testing.T) { Imports: []string{"sort"}, }, }, + "dotgodir/.m1p": { + P: Package{ + ImportPath: "dotgodir/.m1p", + CommentPath: "", + Name: "m1p", + Imports: []string{ + "github.com/golang/dep/internal/gps", + "os", + "sort", + }, + }, + }, }, }, },