Repository navigation
feat(pre-commit): Add commitizen-branch hook - #517
Conversation
Codecov Report
@@ Coverage Diff @@
## master #517 +/- ##
==========================================
- Coverage 98.25% 97.93% -0.33%
==========================================
Files 39 39
Lines 1551 1551
==========================================
- Hits 1524 1519 -5
- Misses 27 32 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
cb81b4e to
01ce73b
Compare
In v2.27.1, the commitizen pre-commit hook began specifying that it runs on the commit-msg stage in .pre-commit-hooks.yaml, so it is no longer necessary to specify the hook stage when using the hook in .pre-commit-config.yaml.
01ce73b to
d630184
Compare
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.
|
Users can certainly write their own pre-commit hooks, but I consider them tricky to write and test since many implementations I see that haven't already been reviewed by the author of pre-commit get details wrong. I also believe many users will not be aware that the commit-msg hook relies on the developer to have installed the pre-commit hooks correctly since it can't be run in CI. It is a good hook in that it offers real-time feedback, but it is also trivially circumvented (most likely by accident). Tools like pre-commit.ci, pre-commit/pre-commit-action, and ScribeMD/pre-commit-action make it trivial to run the proposed pre-push hook in CI, which is not possible with the existing commit-msg hook. |
d630184 to
bd4aa6f
Compare
|
The test failures seem unrelated to this pull request. |
Description
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. I wasn't sure whether it would be appropriate to add a section to this documentation.
Remove no longer needed
commit-msgstage from self-use ofcommitizenpre-commit hook in.pre-commit-config.yaml. In v2.27.1, thecommitizenpre-commit hook began specifying that it runs on thecommit-msgstage in the hook definition in.pre-commit-hooks.yaml, so it is no longer necessary to specify the hook stage when using the hook in.pre-commit-config.yaml.Checklist
./scripts/formatand./scripts/testlocally to ensure this change passes linter check and testExpected behavior
The
commitizenhook continues to work as before, allowing empty commit messages. Thecommitizen-branchhook checks all commit messages on your branch, and doesn't allow empty commit messages.Steps to Test This Pull Request
Replace your Commitizen hook config in your
.pre-commit-config.yamlwith the following:Ensure that you have pre-commit 1.4.3 or higher installed.
Install
commit-msgandpre-pushhooks if you haven't already via:pre-commit install --hook-type commit-msg pre-push.Commit some changes to your repository.
If the commit message was invalid, the
commitizenhook will fail, and otherwise it will succeed.Commit a change with an empty commit message:
git commit --allow-empty-message -m "".Attempt to push your branch.
The push fails with an error regarding the empty commit message.
Additional context
Follows on #512 and #514.