Skip to content

Commit

Permalink
feature: Exclude by command names too (#335)
Browse files Browse the repository at this point in the history
* feature: Skip by command name given in LEFTHOOK_EXCLUDE env too

Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>

* chore: Add test on skipping by name

Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>

Signed-off-by: Valentin Kiselev <mrexox@evilmartians.com>
  • Loading branch information
mrexox authored Oct 13, 2022
1 parent 976f720 commit 8c70dd3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/full_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ LEFTHOOK=0 git commit -am "Lefthook skipped"

## Skip some tags on the fly

Use LEFTHOOK_EXCLUDE={list of tags to be excluded} for that
Use LEFTHOOK_EXCLUDE={list of tags or command names to be excluded} for that

```bash
LEFTHOOK_EXCLUDE=ruby,security git commit -am "Skip some tag checks"
LEFTHOOK_EXCLUDE=ruby,security,lint git commit -am "Skip some tag checks"
```

## Concurrent files overrides
Expand Down
5 changes: 5 additions & 0 deletions internal/lefthook/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ func (r *Runner) runCommand(name string, command *config.Command) {
return
}

if intersect(r.hook.ExcludeTags, []string{name}) {
logSkip(name, "(SKIP BY NAME)")
return
}

if err := command.Validate(); err != nil {
r.fail(name, "")
return
Expand Down
5 changes: 4 additions & 1 deletion internal/lefthook/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ func TestRunAll(t *testing.T) {
{
name: "with exclude tags",
hook: &config.Hook{
ExcludeTags: []string{"tests"},
ExcludeTags: []string{"tests", "formatter"},
Commands: map[string]*config.Command{
"test": {
Run: "success",
Tags: []string{"tests"},
},
"formatter": {
Run: "success",
},
"lint": {
Run: "success",
Tags: []string{"linters"},
Expand Down

0 comments on commit 8c70dd3

Please sign in to comment.