Skip to content

Commit bd4aa6f

Browse files
feat(pre-commit): Add commitizen-branch hook
Check all commit messages on the current branch. This is useful for checking commit messages after the fact (e.g., pre-push or in CI) since the existing hook only works at commit time. Expand the documentation of the pre-existing commitizen hook to clarify the relationship between them.
1 parent 6e42459 commit bd4aa6f

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

.pre-commit-hooks.yaml

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
- id: commitizen
22
name: commitizen check
3-
description: "Check whether the commit message follows commiting rules"
3+
description: >
4+
Check whether the current commit message follows commiting rules. Allow
5+
empty commit messages by default, because they typically indicate to Git
6+
that the commit should be aborted.
47
entry: cz check
58
args: [--allow-abort, --commit-msg-file]
69
stages: [commit-msg]
710
language: python
811
language_version: python3
912
minimum_pre_commit_version: "1.4.3"
13+
14+
- id: commitizen-branch
15+
name: commitizen check branch
16+
description: >
17+
Check all commit messages that are already on the current branch but not the
18+
default branch on the origin repository. Useful for checking messages after
19+
the fact (e.g., pre-push or in CI) without an expensive check of the entire
20+
repository history.
21+
entry: cz check
22+
args: [--rev-range, origin/HEAD..HEAD]
23+
always_run: true
24+
pass_filenames: false
25+
language: python
26+
language_version: python3
27+
minimum_pre_commit_version: "1.4.3"

docs/README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ cz commit -s
101101
```
102102

103103
### Integrating with Pre-commit
104-
Commitizen can lint your commit message for you with `cz check`.
104+
Commitizen can lint your commit messages for you with `cz check`.
105105
You can integrate this in your [pre-commit](https://pre-commit.com/) config with:
106106

107107
```yaml
@@ -111,14 +111,23 @@ repos:
111111
rev: master
112112
hooks:
113113
- id: commitizen
114+
- id: commitizen-branch
115+
stages: [push]
114116
```
115117
116-
After the configuration is added, you'll need to run
118+
After the configuration is added, you'll need to run:
117119
118120
```sh
119-
pre-commit install --hook-type commit-msg
121+
pre-commit install --hook-type commit-msg pre-push
120122
```
121123

124+
If you aren't using both hooks, you needn't install both stages.
125+
126+
| Hook | Recommended Stage |
127+
| ----------------- | ----------------- |
128+
| commitizen | commit-msg |
129+
| commitizen-branch | pre-push |
130+
122131
Read more about the `check` command [here](check.md).
123132

124133
### Help

0 commit comments

Comments
 (0)