commitlint
commitlint copied to clipboard
Add option to reopen commit message editor on failed validation
Expected Behavior
- You run
git commitcommand in the command line. - Your editor (set by
EDITOR) opens to allow you to enter the commit message. - You enter the message, save changes and quit the editor.
commitlintvalidates the message.- Depending on the validation:
- If the message validated successfully, the commit was made and you're back in the command line
- If the message didn't pass the validation,
commitlintasks you if you want to retry editing the message:- If you say yes, the editor is re-opened with the original message, allowing you to edit it and try again.
- If you say no, you're back in the command line with the editor state lost.
The proposed behavior in point 5 could be enabled/disabled using a configuration option.
Current Behavior
Steps 1-4 are the same as in Expected behavior; only step 5 is different:
- You run
git commitcommand in the command line. - Your editor (set by
EDITOR) opens to allow you to enter the commit message. - You enter the message, save changes and quit the editor.
commitlintvalidates the message.- You are back in the command line no matter if the validation passed:
- If the message validated successfully, the commit was made
- If the message didn't pass the validation, the commit wasn't made and the editor state was lost (though the message was printed). You need to manually copy the message, re-run
git commitand paste it in the commit message editor again (to be able to make that commit and to not need to write the message from the scratch again).
Affected packages
I don't know.
Possible Solution
I don't know.
Context
It's a bit irritating to need to re-run git commit copying the message, every time you make some error and the message won't pass the validation.
I know I could pass the message with a -m flag, which would make this problem less frustrating, but I find using the editor much more convenient, especially that on many occasions I write more than one paragraph in my commit messages.
Your Environment
| Executable | Version |
|---|---|
commitlint --version |
9.1.2 |
git --version |
2.28.0 |
node --version |
14.12.0 |
I believe there exists a more automatic workaround since the last commit attempt is stored in .git/COMMIT_EDITMSG.
For instance here: https://unix.stackexchange.com/questions/590224/is-git-commit-message-recoverable-if-committing-fails-for-some-reason
Can be improved to
git commit --edit --file "$(git rev-parse --git-dir)/COMMIT_EDITMSG"
although these solutions do not seem to work well with the --verbose flag.
Some people also struggle here: https://github.com/pre-commit/pre-commit/issues/833#issuecomment-513504065