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

Commit 06a4f0b

Browse files
authored
Merge pull request #572 from sectioneight/allow-dots
Allow dot-prefixed packages as valid import paths
2 parents e17ccb8 + 36b6d46 commit 06a4f0b

File tree

5 files changed

+44
-20
lines changed

5 files changed

+44
-20
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package dot
6+
7+
// nothing to see here

internal/gps/_testdata/src/disallow/.m1p/a.go renamed to internal/gps/_testdata/src/dotgodir/.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 (
File renamed without changes.

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+
// vcsRoots is a set of directories we should not descend into in ListPackages when
32+
// searching for Go packages
33+
var vcsRoots = 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 := vcsRoots[fi.Name()]; ok {
8597
return filepath.SkipDir
8698
}
8799

internal/gps/pkgtree/pkgtree_test.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,20 +1073,6 @@ 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-
//},
10901076
"disallow/testdata": {
10911077
P: Package{
10921078
ImportPath: "disallow/testdata",
@@ -1280,7 +1266,7 @@ func TestListPackages(t *testing.T) {
12801266
},
12811267
},
12821268
},
1283-
"skip directories starting with '.'": {
1269+
"does not skip directories starting with '.'": {
12841270
fileRoot: j("dotgodir"),
12851271
importRoot: "dotgodir",
12861272
out: PackageTree{
@@ -1292,13 +1278,32 @@ func TestListPackages(t *testing.T) {
12921278
Imports: []string{},
12931279
},
12941280
},
1281+
"dotgodir/.go": {
1282+
P: Package{
1283+
ImportPath: "dotgodir/.go",
1284+
Name: "dot",
1285+
Imports: []string{},
1286+
},
1287+
},
12951288
"dotgodir/foo.go": {
12961289
P: Package{
12971290
ImportPath: "dotgodir/foo.go",
12981291
Name: "foo",
12991292
Imports: []string{"sort"},
13001293
},
13011294
},
1295+
"dotgodir/.m1p": {
1296+
P: Package{
1297+
ImportPath: "dotgodir/.m1p",
1298+
CommentPath: "",
1299+
Name: "m1p",
1300+
Imports: []string{
1301+
"github.com/golang/dep/internal/gps",
1302+
"os",
1303+
"sort",
1304+
},
1305+
},
1306+
},
13021307
},
13031308
},
13041309
},

0 commit comments

Comments
 (0)