Skip to content

Commit

Permalink
fix: properly inherit exclude options when not overwritten (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Jan 20, 2025
1 parent 40e97fc commit 678033f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion internal/lefthook/runner/run_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ func (r *Runner) runJob(ctx context.Context, domain *domain, id string, job *con
case []interface{}:
switch inherited := inheritedDomain.exclude.(type) {
case []interface{}:
// List of globs get appended
inherited = append(inherited, list...)
inheritedDomain.exclude = inherited
default:
// Regex value will be overwritten with a list of globs
inheritedDomain.exclude = job.Exclude
}
default:
case string:
// Regex value always overwrites excludes
inheritedDomain.exclude = job.Exclude
default:
// Inherit
}
groupName := first(job.Name, "group ("+id+")")
inheritedDomain.names = append(inheritedDomain.names, groupName)
Expand Down
13 changes: 9 additions & 4 deletions testdata/exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ stdout '^dir/a.txt dir/b.txt lefthook.yml\s*$'
exec lefthook run -f array
stdout '^dir/a.txt dir/b.txt\s*$'
exec lefthook run -f nested
stdout '^lefthook.yml\s+dir/b.txt lefthook.yml\s+b.txt dir/b.txt\s*$'
stdout '^lefthook.yml\s+dir/b.txt lefthook.yml\s+b.txt dir/b.txt lefthook.yml\s+b.txt dir/b.txt\s*$'

-- lefthook.yml --
skip_output:
Expand Down Expand Up @@ -50,9 +50,14 @@ nested:
- exclude:
- b.txt
run: echo {staged_files}
- exclude:
- '*.yml'
run: echo {staged_files}
- group:
jobs:
- run: echo {staged_files}
- group:
jobs:
- exclude:
- '*.yml'
run: echo {staged_files}
-- a.txt --
a

Expand Down

0 comments on commit 678033f

Please sign in to comment.