From 678033fe1b304d7b014f31bd2b763054dc81fe27 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Mon, 20 Jan 2025 13:13:30 +0300 Subject: [PATCH] fix: properly inherit exclude options when not overwritten (#936) --- internal/lefthook/runner/run_jobs.go | 7 ++++++- testdata/exclude.txt | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/lefthook/runner/run_jobs.go b/internal/lefthook/runner/run_jobs.go index c59720a0..150c002a 100644 --- a/internal/lefthook/runner/run_jobs.go +++ b/internal/lefthook/runner/run_jobs.go @@ -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) diff --git a/testdata/exclude.txt b/testdata/exclude.txt index 0ba0474e..fd6aac8f 100644 --- a/testdata/exclude.txt +++ b/testdata/exclude.txt @@ -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: @@ -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