|
| 1 | +# pre-commit |
| 2 | + |
| 3 | +We run [pre-commit](https://pre-commit.com/) with GitHub Actions so installation on |
| 4 | +your local machine is currently optional. |
| 5 | + |
| 6 | +The pre-commit [configuration file](https://github.com/apache/tooling-docs/blob/main/.pre-commit-config.yaml) |
| 7 | +is in the repository root. Before you can run the hooks, you need to have pre-commit installed. |
| 8 | + |
| 9 | +The hooks run when running `git commit` and also from the command line with `pre-commit`. Some of the hooks will auto |
| 10 | +fix the code after the hooks fail whilst most will print error messages from the linters. If a hook fails the overall |
| 11 | +commit will fail, and you will need to fix the issues or problems and `git add` and `git commit` again. On `git commit` |
| 12 | +the hooks will run mostly only against modified files so if you want to test all hooks against all files and when you |
| 13 | +are adding a new hook you should always run: |
| 14 | + |
| 15 | +`pre-commit run --all-files` |
| 16 | + |
| 17 | +Sometimes you might need to skip a hook to commit because the hook is stopping you from committing or your computer |
| 18 | +might not have all the installation requirements for all the hooks. The `SKIP` variable is comma separated for two or |
| 19 | +more hooks: |
| 20 | + |
| 21 | +`SKIP=typos git commit -m "foo"` |
| 22 | + |
| 23 | +The same applies when running pre-commit: |
| 24 | + |
| 25 | +`SKIP=typos pre-commit run --all-files` |
| 26 | + |
| 27 | +Occasionally you can have more serious problems when using `pre-commit` with `git commit`. You can use `--no-verify` to |
| 28 | +commit and stop `pre-commit` from checking the hooks. For example: |
| 29 | + |
| 30 | +`git commit --no-verify -m "foo"` |
| 31 | + |
| 32 | +If you just want to run one hook for example just run the `markdownlint` hook: |
| 33 | + |
| 34 | +`pre-commit run markdownlint --all-files` |
| 35 | + |
| 36 | +We have a [Makefile](https://github.com/apache/tooling-docs/blob/main/Makefile) in the repository root which has three pre-commit convenience commands. |
| 37 | + |
| 38 | +For example, you can run the following to set up pre-commit to run before each commit |
| 39 | + |
| 40 | +```shell |
| 41 | +make checkinstall |
| 42 | +``` |
0 commit comments