Merge pull request #131 from alaingilbert/fix-ignored_paths

Fix ignored_paths
This commit is contained in:
Alessio Pracchia 2017-11-24 09:01:19 +01:00 committed by GitHub
commit a30bf93f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -397,7 +397,8 @@ func (p *Project) tool(stop <-chan bool, path string) error {
func (p *Project) walk(path string, info os.FileInfo, err error) error { func (p *Project) walk(path string, info os.FileInfo, err error) error {
for _, v := range p.Watcher.Ignore { for _, v := range p.Watcher.Ignore {
s := append([]string{p.Path}, strings.Split(v, string(os.PathSeparator))...) s := append([]string{p.Path}, strings.Split(v, string(os.PathSeparator))...)
if strings.Contains(path, filepath.Join(s...)) { absolutePath, _ := filepath.Abs(filepath.Join(s...))
if path == absolutePath || strings.HasPrefix(path, absolutePath+string(os.PathSeparator)) {
return nil return nil
} }
} }

View File

@ -42,6 +42,7 @@ func TestWalk(t *testing.T) {
{"/go/project", true}, {"/go/project", true},
{"/go/project/main.go", false}, {"/go/project/main.go", false},
{"/go/project/main_test.go", false}, {"/go/project/main_test.go", false},
{"/go/project/vendorish/foo", true},
// invalid relative path // invalid relative path
{"./relative/path", true}, {"./relative/path", true},
{"./relative/path/file.go", false}, {"./relative/path/file.go", false},
@ -66,7 +67,7 @@ func TestWalk(t *testing.T) {
t.Errorf("Exepeted %d files, but was %d", 2, p.files) t.Errorf("Exepeted %d files, but was %d", 2, p.files)
} }
if p.folders != 1 { if p.folders != 2 {
t.Errorf("Exepeted %d folders, but was %d", 2, p.folders) t.Errorf("Exepeted %d folders, but was %d", 2, p.folders)
} }
} }