Search code examples
gitpre-commit-hookpre-commitpre-commit.com

Run pre-commit hook on all pushed files


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?


Solution

  • 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