Closed
Description
Description
Git interprets an empty commit message to mean that a commit should be aborted, but calls all commit-msg hooks anyways. This causes pre-commit hooks that run as commit-msg hooks but don't guard against empty commit messages to spew errors en masse when the commit was already being intentionally aborted.
Steps to reproduce
- Configure commitizen to run as a commit-msg hook using pre-commit as described below.
touch foo && git add && git commit
- Save an empty commit message.
For step 1, add the following to .pre-commit-config.yaml
:
yaml
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.18.1
hooks:
- id: commitizen
stages:
- commit-msg
Current behavior
Pre-commit follows git's lead and calls commitizen when the commit message is empty when run as a commit-msg hook. This leads to the following error:
commitizen check..............................................................Failed
- hook id: commitizen
- exit code: 14
commit validation: failed!
please enter a commit message in the commitizen format.
commit "": "# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch foo
#
# Changes to be committed:
# ,,,
pattern: (build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)(\(\S+\))?!?:(\s.*)
The commit is still correctly aborted of course.
Desired behavior
I expected the commitizen commit-msg hook to silently report success in this case since there is no commit message to check.
Environment
- commitizen version: 2.18.1
- python version: Python 3.9.5
- operating system: Linux