Skip to content

Commit cc6ee90

Browse files
authored
Markdown: add documentation on pre-commit usage (#11680)
1 parent b106d6e commit cc6ee90

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

PRE-COMMIT.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# pre-commit
2+
3+
We run [pre-commit](https://pre-commit.com/) with
4+
[GitHub Actions](https://github.com/apache/cloudstack/blob/main/.github/workflows/linter.yml) so installation on your
5+
local machine is currently optional.
6+
7+
The `pre-commit` [configuration file](https://github.com/apache/cloudstack/blob/main/.pre-commit-config.yaml)
8+
is in the repository root. Before you can run the hooks, you need to have `pre-commit` installed. `pre-commit` is a
9+
[Python package](https://pypi.org/project/pre-commit/).
10+
11+
From the repository root run: `pip install -r requirements-dev.txt` to install `pre-commit` and after you install
12+
`pre-commit` you will then need to install the pre-commit hooks by running `pre-commit install`.
13+
14+
The hooks run when running `git commit` and also from the command line with `pre-commit`. Some of the hooks will auto
15+
fix the code after the hooks fail whilst most will print error messages from the linters. If a hook fails the overall
16+
commit will fail, and you will need to fix the issues or problems and `git add` and `git commit` again. On `git commit`
17+
the hooks will run mostly only against modified files so if you want to test all hooks against all files and when you
18+
are adding a new hook you should always run:
19+
20+
`pre-commit run --all-files`
21+
22+
Sometimes you might need to skip a hook to commit because the hook is stopping you from committing or your computer
23+
might not have all the installation requirements for all the hooks. The `SKIP` variable is comma separated for two or
24+
more hooks:
25+
26+
`SKIP=codespell git commit -m "foo"`
27+
28+
The same applies when running pre-commit:
29+
30+
`SKIP=codespell pre-commit run --all-files`
31+
32+
Occasionally you can have more serious problems when using `pre-commit` with `git commit`. You can use `--no-verify` to
33+
commit and stop `pre-commit` from checking the hooks. For example:
34+
35+
`git commit --no-verify -m "foo"`
36+
37+
If you are having major problems using `pre-commit` you can always uninstall it.
38+
39+
To run a single hook use `pre-commit run --all-files <hook_id>`
40+
41+
For example just run the `codespell` hook:
42+
43+
`pre-commit run --all-files codespell`

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@
10291029
<exclude>CONTRIBUTING.md</exclude>
10301030
<exclude>README.md</exclude>
10311031
<exclude>INSTALL.md</exclude>
1032+
<exclude>PRE-COMMIT.md</exclude>
10321033
<exclude>build/build.number</exclude>
10331034
<exclude>debian/cloudstack-agent.dirs</exclude>
10341035
<exclude>debian/cloudstack-usage.dirs</exclude>

0 commit comments

Comments
 (0)