Skip to content

Commit

Permalink
Allow dot-prefixed packages as valid import paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandella committed May 12, 2017
1 parent 109db8e commit 7200ca3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/gps/_testdata/src/disallow/.m1p/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package m1p
import (
"sort"

"github.com/golang/dep/gps"
"github.com/golang/dep/internal/gps"
)

var (
Expand Down
3 changes: 3 additions & 0 deletions internal/gps/_testdata/src/dotgodir/.go/dot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dot

// nothing to see here
20 changes: 16 additions & 4 deletions internal/gps/pkgtree/pkgtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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
}

Expand Down
33 changes: 19 additions & 14 deletions internal/gps/pkgtree/pkgtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 7200ca3

Please sign in to comment.