Some hooks can take a while to run, and I would like to run those before I push, but not before each particular commit (for example, pylint can be a bit slow).
I've seen the following:
- Question: Using hooks at different stages
- mesos-commits mailing list archives
- Feature request: pre-commit or pre-push only hooks
But it's still not clear to be how I'm supposed to set this up.
Here is what I have tried:
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
stages: [push]
From that I'm expecting the first couple of hooks to run before a commit (which they do), but I'm expecting black to run before pushing, which it doesn't.
To test that I have created the following file:
"""This is a docstring."""
print('this should be formatted')
Which is certainly not being formatted by black.
default_stages
applies to all stages, why is it necessary to specify--hook-type
for these 2 stages? I had this very same problem and my expectation, after reading the doc, was that by not specifying any stages globally, pre-commit would install the hooks configured at the specified stages. Why isn't this so? – Brilliant