-
Notifications
You must be signed in to change notification settings - Fork 551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pre-commit
hook that will run Commitizen on git commit
#801
Comments
Hi @ShaneKosieradzki , if it helps, you can use husky to run pre commit hooks. Install husky:
Then run this to add a pre commit message hook:
Note, you will probably want to add the resulting hook file to git:
I know that isn't enhancing commitizen itself, but it does get you the pre commit hooks Hope that helps! |
That doesn't help if a team already has hooks written for |
+1 for this! Our team just set up the When they run All they would know is that, for some reason, when they run I could totally be thinking about commitizen wrong, but in my mind, it would be so cool if we could achieve this behavior somehow. |
Try with this hook - repo: https://github.com/commitizen-tools/commitizen
rev: master
hooks:
- id: commitizen
stages: [commit-msg] Or if you don't want to add external links to your repo, then create your own local hook in I generally wrap the calls in a
Then in your Makefile .PHONY commitizen
commitizen:
@cz check --commit-msg-file .git/COMMIT_EDITMSG Or if you are not very found of Make, then just call commitizen directly:
Don't forget to tell
For more info on creating custom pre-commit hooks, it's all pretty well documented in their official website pre-commit.com |
@donhector I'm trying to use your hook, and it's failing because commitizen check.........................................................Failed
- hook id: commitizen
- exit code: 13
usage: cz
[-h]
[--debug]
[-n NAME]
{init,commit,c,ls,example,info,schema,bump,changelog,ch,check,version}
...
cz: error: unrecognized arguments: settings.toml Dockerfile .dockerignore Template/config.py .editorconfig .gitignore pyproject.toml tests/conftest.py poetry.lock .pre-commit-config.yaml .github/workflows/python.yml tox.ini README.md Template/logging/__init__.py
Command is required Any tips on how to fix it? Do I need to add any arguments? Thanks |
@lays147 Could you share your |
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-toml
- id: check-yaml
- id: check-docstring-first
- id: detect-aws-credentials
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-check-mock-methods
- id: python-use-type-annotations
- repo: https://github.com/hadolint/hadolint
rev: master
hooks:
- id: hadolint-docker
- repo: local
hooks:
- id: lint and format
name: Lint and format files
entry: poetry run tox -e lint
language: system
- id: compliance and quality
name: Run for compliance and quality checks
entry: poetry run tox -e compliance
language: system
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.20.0
hooks:
- id: commitizen
stages: [commit-msg] |
@lays147 Your
|
@donhector ouch. Thanks for pointing that out. 🙈 Now it works! |
@donhector That pre-commit hook described is for commitizen-tools project which is a different commitizen tool from this one so that is rather misleading for this issue. commitizen/cz-cli a JS commit message creator Summary of my research:
|
If you came across this issue and are trying to fix The error was happening to me because I was using |
Could someone here help me with this?: https://stackoverflow.com/questions/72264186/post-merge-hook-to-commitizen-bump-and-changelog |
@adam-grant-hendry Seems a bit cheeky to post a barely on-topic SO question here but also this is the wrong project to ask for help in, this is a JavaScript project and not commitizen-tools Python based commitizen. |
@cas-- If there was a |
Background
pre-commit is a package manager for git hooks. The project allows hooks to be downloaded locally and run in an isolated environment. This allows for easy adoption of hooks written in a variety of languages and allows for quick adoption by contributors who are unfamiliar with any particular hook.
Possible Solution
This project can make itself
pre-commit
compatible by adding a.pre-commit-hooks.yaml
file. You can use this file to make your existingprepare-commit-msg
hook and the Commitizen project as a whole more accessible.The text was updated successfully, but these errors were encountered: