diff --git a/pipeline/frontend/yaml/constraint/constraint.go b/pipeline/frontend/yaml/constraint/constraint.go index 891db304f..1dee7477a 100644 --- a/pipeline/frontend/yaml/constraint/constraint.go +++ b/pipeline/frontend/yaml/constraint/constraint.go @@ -388,14 +388,19 @@ func (c *Path) Includes(v []string) bool { return false } -// Excludes returns true if the string matches any of the exclude patterns. +// Excludes returns true if all of the strings match any of the exclude patterns. func (c *Path) Excludes(v []string) bool { - for _, pattern := range c.Exclude { - for _, file := range v { + for _, file := range v { + matched := false + for _, pattern := range c.Exclude { if ok, _ := doublestar.Match(pattern, file); ok { - return true + matched = true + break } } + if !matched { + return false + } } - return false + return true } diff --git a/pipeline/frontend/yaml/constraint/constraint_test.go b/pipeline/frontend/yaml/constraint/constraint_test.go index a6c68dffa..7dafd6f99 100644 --- a/pipeline/frontend/yaml/constraint/constraint_test.go +++ b/pipeline/frontend/yaml/constraint/constraint_test.go @@ -233,8 +233,23 @@ func TestConstraintList(t *testing.T) { { conf: "{ include: [ '*.md' ], exclude: [ CHANGELOG.md ] }", with: []string{"README.md", "CHANGELOG.md"}, + want: true, + }, + { + conf: "{ exclude: [ CHANGELOG.md ] }", + with: []string{"README.md", "CHANGELOG.md"}, + want: true, + }, + { + conf: "{ exclude: [ CHANGELOG.md, docs/**/*.md ] }", + with: []string{"docs/main.md", "CHANGELOG.md"}, want: false, }, + { + conf: "{ exclude: [ CHANGELOG.md, docs/**/*.md ] }", + with: []string{"docs/main.md", "CHANGELOG.md", "README.md"}, + want: true, + }, // commit message ignore matches { conf: "{ include: [ README.md ], ignore_message: '[ALL]' }",