diff --git a/internal/lefthook/runner/run_jobs.go b/internal/lefthook/runner/run_jobs.go index 97ee68d4..30ea77cc 100644 --- a/internal/lefthook/runner/run_jobs.go +++ b/internal/lefthook/runner/run_jobs.go @@ -25,8 +25,9 @@ var ( type domain struct { failed *atomic.Bool - glob string - root string + glob string + root string + onlyJobs []string } func (r *Runner) runJobs(ctx context.Context) []Result { @@ -36,7 +37,7 @@ func (r *Runner) runJobs(ctx context.Context) []Result { resultsChan := make(chan Result, len(r.Hook.Jobs)) var failed atomic.Bool - domain := &domain{failed: &failed} + domain := &domain{failed: &failed, onlyJobs: r.RunOnlyJobs} for i, job := range r.Hook.Jobs { id := strconv.Itoa(i) @@ -82,7 +83,7 @@ func (r *Runner) runJob(ctx context.Context, domain *domain, id string, job *con } if len(job.Run) != 0 || len(job.Script) != 0 { - if len(r.RunOnlyJobs) != 0 && !slices.Contains(r.RunOnlyJobs, job.Name) { + if len(domain.onlyJobs) != 0 && !slices.Contains(domain.onlyJobs, job.Name) { return skipped(job.PrintableName(id)) } @@ -95,13 +96,8 @@ func (r *Runner) runJob(ctx context.Context, domain *domain, id string, job *con inheritedDomain.root = first(job.Root, domain.root) groupName := first(job.Name, "["+id+"]") - if len(r.RunOnlyJobs) != 0 && slices.Contains(r.RunOnlyJobs, job.Name) { - children := make([]string, len(job.Group.Jobs), 0) - for _, child := range job.Group.Jobs { - children = append(children, child.Name) - } - - r.RunOnlyJobs = append(r.RunOnlyJobs, children...) + if len(domain.onlyJobs) != 0 && slices.Contains(domain.onlyJobs, job.Name) { + inheritedDomain.onlyJobs = []string{} } return r.runGroup(ctx, groupName, &inheritedDomain, job.Group)