From 0fe7ff8d3c37bf73242191467556c1bc18dfbc47 Mon Sep 17 00:00:00 2001 From: Gilbert Roulot Date: Thu, 11 Jan 2018 12:09:13 +0100 Subject: [PATCH] Fixes filtering of IgnoredPaths to work on the path and not filename, add test for it. --- dependency/dependency_file.go | 11 ++++++++--- dependency/dependency_file_test.go | 2 ++ .../test_get_local_dependency_files/sub1/sub2/Gemfile | 0 .../test_get_local_dependency_files/sub3/sub4/Gemfile | 0 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 dependency/testdata/test_get_local_dependency_files/sub1/sub2/Gemfile create mode 100644 dependency/testdata/test_get_local_dependency_files/sub3/sub4/Gemfile diff --git a/dependency/dependency_file.go b/dependency/dependency_file.go index 1a673a8..4046ab7 100644 --- a/dependency/dependency_file.go +++ b/dependency/dependency_file.go @@ -165,14 +165,19 @@ var getLocalDependencyFiles = func(rootPath string) ([]*api.DependencyFile, erro } } // Skip ignored_pathes - for _, ignoredPath := range config.IgnoredPaths { - matched, err := filepath.Match(filepath.Clean(ignoredPath), info.Name()) + // Old behavior, keep it in case users rely on it + matched1, err := filepath.Match(filepath.Clean(ignoredPath), info.Name()) + if err != nil { + return err + } + // Actual match on the path + matched2, err := filepath.Match(filepath.Clean(ignoredPath), relativePath) if err != nil { return err } - if matched { + if matched1 || matched2 { fmt.Println("Skipping", info.Name()) return filepath.SkipDir } diff --git a/dependency/dependency_file_test.go b/dependency/dependency_file_test.go index 1523373..3df0ed8 100644 --- a/dependency/dependency_file_test.go +++ b/dependency/dependency_file_test.go @@ -15,6 +15,7 @@ import ( "path/filepath" "reflect" "encoding/json" + "github.com/gemnasium/toolbelt/config" ) type TestFile struct { @@ -172,6 +173,7 @@ func TestGetLocalDependencyFiles(t *testing.T) { b, _ := json.MarshalIndent(v, "", " ") return string(b) } + config.IgnoredPaths = []string{"sub1/sub2/Gemfile", "sub3/sub4"} // Get a list of recognised dependency files from test data result, err := getLocalDependencyFiles(filepath.Join("testdata", "test_get_local_dependency_files")) if err != nil { diff --git a/dependency/testdata/test_get_local_dependency_files/sub1/sub2/Gemfile b/dependency/testdata/test_get_local_dependency_files/sub1/sub2/Gemfile new file mode 100644 index 0000000..e69de29 diff --git a/dependency/testdata/test_get_local_dependency_files/sub3/sub4/Gemfile b/dependency/testdata/test_get_local_dependency_files/sub3/sub4/Gemfile new file mode 100644 index 0000000..e69de29