3

The basic version of my setup is to have pre-commit run a code linter. However I find it too long / inconvenient when it checks/rejects individual commits, instead I'd like to run it once I try to push my code to the remote / CI. I found that I can configure stages, so I decided to put only push stage as default for all my hooks. However, it ends up just letting the non-linted code be pushed. Perhaps it's because it doesn't recognize this code as "changed", as it runs on subset of all files?

Here is my pre-commit config:

default_stages: [push]
repos:
-   repo: https://github.com/ambv/black
    rev: 19.10b0
    hooks:
    - id: black
      language_version: python3

If it's technically impossible to run it only on the files I'm changing with this push, can I just run it on all files somehow?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Yodogawa Mikio
  • 413
  • 3
  • 9

1 Answers1

4

you need to make sure you install pre-commit for whatever stage you're using

for example from the pre-commit during push docs:

To use pre-push hooks with pre-commit, run:

$ pre-commit install --hook-type pre-push
pre-commit installed at .git/hooks/pre-push

disclaimer: I created pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • I'm surprised it's not installed there by default given that config determines if there's anything to do or not. Thanks for explaining. – Yodogawa Mikio Jul 09 '21 at 15:34
  • the `default_stages` you set only overrides tools which don't set `stages` explicitly ([as documented](https://pre-commit.com/#top_level-default_stages)) – anthony sottile Jul 09 '21 at 17:08