captainhook
captainhook copied to clipboard
Relaunch editor if message is invalid or save to tempoarary file?
Currently if I type a commit message and it is rejected, then I have to commit again, and re-type everything (which could have been a significant amount of code).
Would be good to automatically respawn the editor (using the EDITOR env var f.e.) with an additional comment showing the validation failures.
Or, I guess, to simply save the commit message to a temporary file where it can be re-sourced.
This can get very difficult if you are not using the command line to commit e.g. your IDE or other GUI tools. I'll have a look at the possibilities to make this a bit easier. For now the whole message is printed back to you if a message rule failed.
If you write your own message validation you could include the previous message into the output as well. At least this way you can copy & paste it.
@sebastianfeldmann just came across this blog post, maybe it helps to solve this issue https://pacurar.dev/automating-the-git-commit-message-prefix/
@shochdoerfer this actually triggered some ideas, let's see what I can come up with. Thanks ;)
This can now be done in a way were you at least can store the commit message into a temporary file and use that file to reload the message for the next commit.
To achieve this you have to configure two actions.
- One to prepare the commit message from a file
- One to write the file on a failed commit
{
"prepare-commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\CaptainHook\\App\\Hook\\Message\\Action\\PrepareFromFile",
"options": {
"file": ".git/CH_COMMIT_MESSAGE.tmp"
}
}
]
}
"commit-msg": {
"enabled": true,
"actions": [
{
"action": "\\CaptainHook\\App\\Hook\\Message\\Action\\CacheOnFail",
"options": {
"file": ".git/CH_COMMIT_MESSAGE.tmp"
}
}
]
}
}