Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #572 from sectioneight/allow-dots
Browse files Browse the repository at this point in the history
Allow dot-prefixed packages as valid import paths
  • Loading branch information
sdboyer committed May 16, 2017
2 parents e17ccb8 + 36b6d46 commit 06a4f0b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
7 changes: 7 additions & 0 deletions internal/gps/_testdata/src/dotgodir/.go/dot.go
Original file line number Diff line number Diff line change
@@ -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
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
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)
}

// 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.
//
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 := vcsRoots[fi.Name()]; ok {
return filepath.SkipDir
}

Expand Down
35 changes: 20 additions & 15 deletions internal/gps/pkgtree/pkgtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand All @@ -1292,13 +1278,32 @@ 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",
Name: "foo",
Imports: []string{"sort"},
},
},
"dotgodir/.m1p": {
P: Package{
ImportPath: "dotgodir/.m1p",
CommentPath: "",
Name: "m1p",
Imports: []string{
"github.com/golang/dep/internal/gps",
"os",
"sort",
},
},
},
},
},
},
Expand Down

0 comments on commit 06a4f0b

Please sign in to comment.