Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pre-install pre commit into hooks into docker

As I understand the documentation, whenever I add these lines to the config:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.1.0
    hooks:
    -   id: trailing-whitespace

it makes pre-commit to download the hooks code from this repo and execute it. Is it possible to pre-install all the hooks somehow into a Docker image. So when I call pre-commit run no network is used?

I found this section of the documentation describing how pre-commit caches all the repositories. They are stored in ~/.cache/pre-commit and this could be configured by updating PRE_COMMIT_HOME env variable.

However, the caching only works when I do pre-commit run. But I want to pre-install everything w/o running the checks. Is it possible?

like image 331
ivaigult Avatar asked May 08 '26 20:05

ivaigult


1 Answers

you're looking for the pre-commit install-hooks command

at the least you need something like this to cache the pre-commit environments:

COPY .pre-commit-config.yaml .
RUN git init . && pre-commit install-hooks

disclaimer: I created pre-commit

like image 197
Anthony Sottile Avatar answered May 11 '26 15:05

Anthony Sottile