Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop pre-commit on failure?

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.

like image 897
Mark C. Avatar asked Mar 25 '26 07:03

Mark C.


1 Answers

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

like image 69
Anthony Sottile Avatar answered Mar 27 '26 03:03

Anthony Sottile



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!