Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude by command names too #335

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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