Skip to content

Commit ab3f43d

Browse files
Kurt-von-LavenLee-W
authored andcommitted
fix(pre-commit): Confine hook to commit-msg stage
The Commitizen pre-commit hook runs cz check, which only makes sense to do on a commit message, not at other Git hook stages. By default the hook is currently run on staged files pre-commit, which is nonsensical unless the files in the repository themselves contain Git commit messages. The hook is an implausible candidate even for the prepare-commit-msg stage since this stage is intended for hooks that modify the commit message rather than check it. Specifying the hook stage centrally makes it less error-prone to use and saves one line of configuration for users of the pre-commit hook.
1 parent b787e64 commit ab3f43d

File tree

5 files changed

+3
-4
lines changed

5 files changed

+3
-4
lines changed

‎.pre-commit-hooks.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name: commitizen check
33
description: "Check whether the commit message follows commiting rules"
44
entry: cz check --commit-msg-file
5+
stages: [commit-msg]
56
language: python
67
language_version: python3
78
minimum_pre_commit_version: "1.4.3"

‎commitizen/commands/init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _install_pre_commit_hook(self):
114114
cz_hook_config = {
115115
"repo": "https://github.com/commitizen-tools/commitizen",
116116
"rev": f"v{__version__}",
117-
"hooks": [{"id": "commitizen", "stages": ["commit-msg"]}],
117+
"hooks": [{"id": "commitizen"}],
118118
}
119119

120120
config_data = {}

‎docs/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ repos:
111111
rev: master
112112
hooks:
113113
- id: commitizen
114-
stages: [commit-msg]
115114
```
116115
117116
After the configuration is added, you'll need to run

‎docs/auto_check.md

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ repos:
2222
rev: v1.17.0
2323
hooks:
2424
- id: commitizen
25-
stages: [commit-msg]
2625
```
2726
2827
* Step 3: Install the configuration into git hook through `pre-commit`

‎tests/commands/test_init_command.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def ask(self):
2121
cz_hook_config = {
2222
"repo": "https://github.com/commitizen-tools/commitizen",
2323
"rev": f"v{__version__}",
24-
"hooks": [{"id": "commitizen", "stages": ["commit-msg"]}],
24+
"hooks": [{"id": "commitizen"}],
2525
}
2626

2727
expected_config = (

0 commit comments

Comments
 (0)