Search code examples
githookegitjgitcommit-message

Custimize Error Message for hook "commit-msg" in Egit on Windows


As the title says .. I am trying to set up a commit-msg hook in an eclipse project/git repo. I just added the script into my .git folder and from the command line the hook triggers, and i get my Error message.

#!/bin/bash

ISSUE_KEY=`some-regex`
if [ "" ==  "$ISSUE_KEY" ]; then
echo 'Commit rejected - Please edit your commit message'
exit 1;
fi

in Eclipse the hook didnt trigger at first, but after i installed Cygwin, it worked. The Problem is though, that i just get a default prompt saying

Commit was aborted by hook - Rejected by "commit-msg" hook

And not the message from the "echo output". Is there a way to customize my Error message for egit?


Solution

  • Had the same issue, EGIT is horrible concerning all GIT operation, in general I prefer using some external tool to manage all GIT operations. Git bash or GitExtentions, etc.

    But since I have to support other users in Eclipse, I found out the following: 1. Use Eclipse Oxygen so eclipse will at least run the hooks. I found that Luna will not execute them at all on Windows.

    AND

    1. Install Cygwin, or at least make the "sh.exe" in C:\cygwin\bin folder. Eclipse uses this file to execute the hook

    2. Write all the hooks output to some file, e.g. C:\Temp\hooks_log.txt and when it fails check inside that log file

      {
          ....
          My hook code
          ....
      } |& tee /c/temp/MyHook.log
      

    The other option is you are more than welcome to fix the EGIT so it will show the log.