commitizen / cz-cli

The commitizen command line utility. #BlackLivesMatter

Home Page:http://commitizen.github.io/cz-cli/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cz opens editor after CLI successfully build commit message

rafae2k opened this issue · comments

commented

I'm using husky, commitzen and commitlint to setup my commit messages.

i added a prepare-commit-msg hook on husky to create my commit using commitzen cli. It all works perfectly, but when i finish my message on cli it opens the editor, and only when i close the editor it successfully create my commit.

I'm having the same experience as @rafae2k. Seems to be a known issue already though. See #839 from '21.

If you add this hook, you should use git commit to start it

BTW: This is not recommended to add this hook

  • Because it will change the original behavior of git commit, so that will lose fast commit methods such as git commit -m "xxx"
  • And it will eventually open vi so that will lose the convenience of using the CLI
commented

@Zhengqbbb i have all hooks, following git workflow.

pre-commit - runs lintstaged
prepare-commit-msg - runs cz
commit-msg - runs commitlint

even though with or without commit-msg when prepare-commit-msg it opens editor (vim, code, etc...)

prepare-commit-msg - runs cz

Let's see why
The first is the name of the hook, think about what it means: prepare-commit-msg.
And then is the hook behavior, why does the editor open. You can try running the command git commit in other projects without hooks.

Anyway, this hook is triggered once the commit message is added, and the hook running the command will eventually become git commit , and it will automatically open the editor to edit your .git/COMMIT_EDITMSG file.

https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks search text: prepare-commit-msg

BTW As a CLI shouldn't use that hook for launching, I think it's wrong
https://cz-git.qbenben.com/cli/install.html#as-git-hooks-use

ref: #934 (comment)

git config --local core.editor cat

image