From 8a432a6b83c10773d501cd0b4def42afbf210ff5 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Tue, 1 Apr 2025 20:05:51 +0200 Subject: [PATCH] Fix exclude path constraint behavior (#5042) Co-authored-by: Robert Kaussow --- pipeline/frontend/yaml/constraint/constraint.go | 15 ++++++++++----- .../frontend/yaml/constraint/constraint_test.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) 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]' }",