Fix exclude path constraint behavior (#5042)

Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
This commit is contained in:
Ralf Haferkamp 2025-04-01 20:05:51 +02:00 committed by GitHub
parent 47e6d159d1
commit 8a432a6b83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 5 deletions

View file

@ -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
}

View file

@ -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]' }",