captainhook icon indicating copy to clipboard operation
captainhook copied to clipboard

Relaunch editor if message is invalid or save to tempoarary file?

Open dantleech opened this issue 6 years ago • 3 comments
trafficstars

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.

dantleech avatar Jun 10 '19 14:06 dantleech

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 avatar Jun 12 '19 21:06 sebastianfeldmann

@sebastianfeldmann just came across this blog post, maybe it helps to solve this issue https://pacurar.dev/automating-the-git-commit-message-prefix/

shochdoerfer avatar Apr 07 '22 06:04 shochdoerfer

@shochdoerfer this actually triggered some ideas, let's see what I can come up with. Thanks ;)

sebastianfeldmann avatar Apr 07 '22 19:04 sebastianfeldmann

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"
                }
            }
        ]
    }
}

sebastianfeldmann avatar Oct 28 '22 14:10 sebastianfeldmann