7

I have two git pre-commit hooks enabled in pre-commit-config.yml:

  1. A code formatting hook that takes very little time
  2. Our pytest hook, which takes much more time

When (1) updates code formatting, it fails, but (2) still runs. Then (1) and (2) must be run again, doubling the time it takes to run the commit. I'd rather run (1) and run (2) only if (1) passes. Is that possible using pre-commit, and if so, how would I do it? I've plumbed the depths fo the documentation but so far I've been unable to find anything useful.

Mark C.
  • 1,773
  • 2
  • 16
  • 26

1 Answers1

14

I would not recommend having slow checks in pre-commit, you're likely to have your developers disable / ignore it / context switch

that said, there's an option specifically designed for this, the fail_fast option

it's a top level option so you'd set it like this:

fail_fast: true

repos:
# ...

disclaimer: I created pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207