You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have setup this package following the instructions and have the wizard running. This uses husky and the prepare-commit-message hook runs exec < /dev/tty && npx --no-install git-cz --hook || true.
Then the commit-msg hook runs npx --no -- commitlint --edit "\${1}" to lint the commit message.
The trouble i'm facing is that every time i complete the wizard i'm dumped back into the vim in what looks like the COMMIT_EDITMSG git hook asking me to enter a commit message, and have to :q to exit which is annoying. Linting then runs after this as expected.
Steps to reproduce:
Run git commit -a in terminal
Proceed through wizard and choose Yes to the confirmCommit message.
Vim starts, :q to exit
Linting runs.
If i comment out the linting stage i do not enter the COMMIT_EDITMSG hook, so from what i can tell, this opens because the --edit flag of Commitlint says: read last commit message from the specified file or fallbacks to ./.git/COMMIT_EDITMSG so looking at my lint command npx --no -- commitlint --edit "\${1}" - is the path/file not being passed correctly from cz to commitlint? Or is the git process thinking it also needs to launch?
In fact, it is very not recommended to add commit-msg hook~ It will change the default git commit command. E.g, you can't quickly perform "git commit -m ..."
Is there any solution for this problem? It's ridiculous to try to edit it every time. Otherwise, the package has no meaning. @atomicrobokid were you able to fix this?
Maybe next month I'll write a post explaining why this is a problem and how to resolve, until then can follow this thread Zhengqbbb/cz-git#87
Hi @Zhengqbbb, thanks for the above workaround. Have you written the mentioned post yet?
Kind regards,
🤩 I have been busy in the last half year, even weekends, but you reminded me that see my sharing, I will prepare it, and I will reply to you after posting the article.
This should achieve the desired effect of commitizen fully taking over the commit command without exiting into vim or logging any superfluous messages.
You can also place the .gitconfig somewhere else and update the prepare script accordingly. I placed mine in the .husky folder to keep things tidy.
Activity
Zhengqbbb commentedon Jun 17, 2022
In fact, it is very not recommended to add
commit-msghook~ It will change the default git commit command. E.g, you can't quickly perform "git commit -m ..."dwhoban commentedon Aug 23, 2022
+1 on this. Currently the existing husky integration with a prepare-commit-msg hook is broken and exits to an editor screen.
Not sure what you mean @Zhengqbbb, the point of using husky with commitizen is to enforce commitizen usage on all commits.
Zhengqbbb commentedon Aug 23, 2022
Yep~ when u use
prepare-commit-msghook. it mean will enforce open editor(the behavior is
git commitnotgit commit -mahmetkuslular commentedon Jan 3, 2023
Is there any solution for this problem? It's ridiculous to try to edit it every time. Otherwise, the package has no meaning.
@atomicrobokid were you able to fix this?
ghacosta commentedon Feb 27, 2023
same here, looking for a fix on this annoying behaviour.
Zhengqbbb commentedon Feb 28, 2023
Hi guys, I am the author of cz-git and this is the only solution to alias your git command.
.zshrcor.bashrcand restart your terminalMaybe next month I'll write a post explaining why this is a problem and how to resolve, until then can follow this thread
Zhengqbbb/cz-git#87
mrkpatchaa commentedon Aug 5, 2023
I fixed the issue on my side by using the solution provided here
https://gist.github.com/webbertakken/c2b457d39224baf701c8de1589b61555#file-pre-commit-sh-L7
if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then exec >/dev/tty 2>&1; fiNow the wizard will exit and my commitlint will run immediately instead of entering COMMIT_EDITMSG.
EDIT: August 9.
Just to complete my last answer. It works only if you run like this
git commit -m ""aaccioly commentedon Sep 21, 2023
Hi @Zhengqbbb, thanks for the above workaround. Have you written the mentioned post yet?
Kind regards,
Zhengqbbb commentedon Sep 21, 2023
🤩 I have been busy in the last half year, even weekends, but you reminded me that see my sharing, I will prepare it, and I will reply to you after posting the article.
ArturMoczulski commentedon Nov 4, 2023
Got a dirty solution here (using husky) by stubbing the editor with
echowhich runs and quits immediately.package.json:.gitconfigin project root:This will still produce the following message:
However, it does achieve the goal of not opening a Vim or VS Code when using
prepare-commit-msghookdanielbayley commentedon Mar 6, 2024
@ArturMoczulski FYI, if you configure the
core.editorto becatinstead ofecho, that will avoid thehint:.@Zhengqbbb There must be a better way? Maybe making use of the
GIT_EDITORenvironment variable somewhere in thecommitlifecycle?Zhengqbbb commentedon Mar 7, 2024
@danielbayley
!!! Awesome !!! It work well~ 🤩
SET) and linux ...Can add project scripts (like pnpm's postinstall) to help other project collaborator
lawren commentedon May 14, 2024
Just to clarify what I think @danielbayley was getting at:
Create
.gitconfigin project root:Add to package.json:
Reinstall your packages with
npm i,bun i, etc.This should achieve the desired effect of commitizen fully taking over the
commitcommand without exiting into vim or logging any superfluous messages.You can also place the
.gitconfigsomewhere else and update thepreparescript accordingly. I placed mine in the.huskyfolder to keep things tidy.shtev21 commentedon Sep 15, 2024
So what would happen when someone tries to run something like
git rebase -i?I don't think setting the default editor to cat is a sensible approach to resolving this issue.