'pre-commit hooks terminate if previous stage fails
I'm using the pre-commit hooks configuration https://pre-commit.com/ to enable pre-commit hooks
repos:
- repo: local
hooks:
- id: pytest-check
name: pytest-check
entry: pytest
language: system
pass_filenames: false
always_run: false
- id: flake8
name: flake8
entry: flake8
language: python
types: [python]
args: ['src/']
If pytest-check fails it will also execute the flake8 hook.
Is it possible to terminate the execution if a previous hook failed, in this case flake8 would not run if the pytest-check failed.
I read through the docs but couldn't find any information on this...
Solution 1:[1]
you're looking for fail_fast: true
it can be specified both at the top level and at the hook level
an aside you have a few unrelated problems with your configuration:
- ~generally you don't want to run tests as part of
pre-commit, they'll be slow which will frustrate your users and often lead to them turning the whole thing off always_run: falseis the default, no need to specify it- flake8 as you've configured it is both double-linting and fork bombing (you're passing
src/and pre-commit is additionally passing filenames, and you've misconfigured the multiprocessing mode) -- I'd recommend using thepycqa/flake8repository directly which configures this correctly - for
repo: localhooks there's no reason to useargs-- just specify it directly inentry
disclaimer: I wrote pre-commit
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anthony Sottile |
