Automatically apply changes and retry or only run if previous hooks succeeded
See original GitHub issueHi,
First of all thanks for the awesome framework. Pre-commit is great 👏
I often find myself running pre-commit by adding my changes with git add
and then committing. Then, typically it will “fail” because just one or two lines will be fixed by one of the hooks (typically black
), and I will re-run the git commands once more to finish committing my changes.
This doesn’t take much effort, but running everything twice it is a pattern I repeat almost every time I commit something: Would you ever consider adding an option to automatically re-committing the changes made by individual hooks? As in, say you could specify in the config that if black
makes changes, pre-commit should simply add those changes to the staged diff, before running the hook once more, and then running the remaining hooks?
To prevent the xy problem: the underlying reason why running pre-commit twice can sometimes be inconvenient in the first place, is because we have several static checkers like flake8
and mypy
which we don’t really want to run until all code changes are out of the way. Our mypy
hook in particular can take up to 10-15 seconds to run, and as a consequence I will usually interrupt pre-commit after the first few hooks have run (if one “failed”) and re-run all commands.
Finally, I recognise that there might be good reasons why this doesn’t make sense; that pre-commit could be built in a way where it’s not worth a complete restructuring to implement such a feature; or that perhaps my workflow is just sub-optimal, so this is primarily a question over a feature request 🙂
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
yes that’s the
fail_fast
optionThanks 👏👏👏👏
EDIT: I guess what I was after was a hook-level fail-fast option, but I discovered a new setting I didn’t know about that solves the same issue: I’ve specified mypy to run on push instead of commit 🎉