0

I have implemented a commit hook to check the commit message and abort the commit if the message isn't formatted correctly. I've done this with the commit-msg hook.

However, this will only work if you commit with the -m flag. If you omit that flag (because you want to use your editor to add the message), then the commit hook will fail (no message).

From what I have read, both the pre-commit and commit-msg hook are fired before the editor is opened. Is there a way to do something similar that waits for the editor to be closed?

Cjmarkham
  • 9,484
  • 5
  • 48
  • 81

1 Answers1

1

Actually, the commit-msg hook is fired once the message is ready (so, after the user closes the editor), this hook is getting a path to a file with the message value.

From the docs:

The commit-msg hook takes one parameter, which again is the path to a temporary file that contains the commit message written by the developer.

Zacharya Haitin
  • 338
  • 2
  • 9
  • Yeah, it looks like it's an issue with the editor. Using vim works fine but using something like VSCode doesn't. Maybe because the terminal loses focus or something – Cjmarkham Dec 07 '19 at 22:20
  • 1
    Maybe this answer will solve it (--wait): https://stackoverflow.com/a/2596835/4039952 – Zacharya Haitin Dec 08 '19 at 09:41