Search code examples
gitgithookstortoisegitgithub-desktop

Git GUIs ignore commit-msg hook


I wrote a commit-msg hook to check commit messages to use a proper format. When using git bash it works just as intended:

$ git commit -m "test"

[Invalid Commit Message]
------------------------
Commit message needs to start with an uppercase character and be imperative

Example: Add new character model
Regex: ^[A-Z](?!\w*ed).*$
Actual commit message: "test"
Actual length: 5

When using a Git GUI (testet with Tortoise Git and GitHub for Desktop) though it accepts the exact same commit message. It seems to just ignore the hook.

Do Git GUIs just not execute this hook?

Update: I found out that the hook is being executed by tortoise git it just has an error because of the charset in use: ""grep: -P supports only unibyte and UTF-8 locales

I could fix this issue with "LC_ALL=en_US.utf8" (see here)

Tortoise Git now blocks broken commit messages but Github Desktop still seems to ignore the hook. Unlike Tortoise though I cannot see what it is doing internally.


Solution

  • LC_ALL=en_US.utf8 is the correct solution.

    It just has to be part of the same line as the grep command. I tried setting it at the top of the file which somehow worked for Tortoise but not GitHub Desktop.

    This is the solution:

    if [[ $(LC_ALL=en_US.utf8 grep -Pc '^[A-Z].*$' <<< ${title} ) == 0 ]];
    

    GitHub desktop outputs the stderr output only if the the script explicitly outputs an exit code other than 0. It does not output any errors when the script fails.