diff --git a/internal/gps/_testdata/src/dotgodir/.go/.gitkeep b/internal/gps/_testdata/src/dotgodir/.go/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/gps/_testdata/src/dotgodir/foo.go/.gitkeep b/internal/gps/_testdata/src/dotgodir/foo.go/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/gps/_testdata/src/dotgodir/foo.go/foo.go b/internal/gps/_testdata/src/dotgodir/foo.go/foo.go new file mode 100644 index 0000000000..1de8b0ab15 --- /dev/null +++ b/internal/gps/_testdata/src/dotgodir/foo.go/foo.go @@ -0,0 +1,12 @@ +// 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 foo + +import "sort" + +var _ = sort.Strings + +// yes, this is dumb, don't use ".go" in your directory names +// See https://github.com/golang/dep/issues/550 for more information diff --git a/internal/gps/pkgtree/pkgtree.go b/internal/gps/pkgtree/pkgtree.go index a83fb4e034..a6b452764d 100644 --- a/internal/gps/pkgtree/pkgtree.go +++ b/internal/gps/pkgtree/pkgtree.go @@ -199,10 +199,17 @@ func fillPackage(p *build.Package) error { var testImports []string var imports []string for _, file := range gofiles { - // Skip underscore-led files, in keeping with the rest of the toolchain. - if filepath.Base(file)[0] == '_' { + // Skip underscore-led or dot-led files, in keeping with the rest of the toolchain. + bPrefix := filepath.Base(file)[0] + if bPrefix == '_' || bPrefix == '.' { continue } + + // Skip any directories that happened to get caught by glob + if stat, err := os.Stat(file); err == nil && stat.IsDir() { + continue + } + pf, err := parser.ParseFile(token.NewFileSet(), file, nil, parser.ImportsOnly|parser.ParseComments) if err != nil { if os.IsPermission(err) { diff --git a/internal/gps/pkgtree/pkgtree_test.go b/internal/gps/pkgtree/pkgtree_test.go index 1cecf65cf6..9371900079 100644 --- a/internal/gps/pkgtree/pkgtree_test.go +++ b/internal/gps/pkgtree/pkgtree_test.go @@ -1280,6 +1280,28 @@ func TestListPackages(t *testing.T) { }, }, }, + "skip directories starting with '.'": { + fileRoot: j("dotgodir"), + importRoot: "dotgodir", + out: PackageTree{ + ImportRoot: "dotgodir", + Packages: map[string]PackageOrErr{ + "dotgodir": { + P: Package{ + ImportPath: "dotgodir", + Imports: []string{}, + }, + }, + "dotgodir/foo.go": { + P: Package{ + ImportPath: "dotgodir/foo.go", + Name: "foo", + Imports: []string{"sort"}, + }, + }, + }, + }, + }, } for name, fix := range table {