Skip to content

Commit

Permalink
feat: use glob in exclude array
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Jul 22, 2024
1 parent f818fe5 commit a0f6749
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 6 additions & 4 deletions internal/lefthook/runner/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ func byExclude(vs []string, matcher interface{}) []string {

return vsf
case []interface{}:
excludeNames := make(map[string]struct{}, len(exclude))
globs := make([]glob.Glob, 0, len(exclude))
for _, name := range exclude {
excludeNames[name.(string)] = struct{}{}
globs = append(globs, glob.MustCompile(name.(string)))
}

vsf := make([]string, 0)
for _, v := range vs {
if _, excluded := excludeNames[v]; !excluded {
vsf = append(vsf, v)
for _, g := range globs {
if ok := g.Match(v); !ok {
vsf = append(vsf, v)
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions testdata/exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ stdout 'excluded.txt lefthook.yml not-excluded.txt'
exec lefthook run -f regexp
stdout 'lefthook.yml not-excluded.txt'
exec lefthook run -f array
stdout 'lefthook.yml not-excluded.txt'
stdout 'not-excluded.txt'

-- lefthook.yml --
skip_output:
Expand All @@ -25,14 +25,15 @@ regexp:
commands:
echo:
run: echo {staged_files}
exclude: '^excluded.txt'
exclude: '^excluded\.[tx]+'

array:
commands:
echo:
run: echo {staged_files}
exclude:
- exclude.txt
- '*.yml'

-- not-excluded.txt --
sometext
Expand Down

0 comments on commit a0f6749

Please sign in to comment.