How to get Git Commit message in Git Tower?

I am using this script in githook commit-msg.

#!/usr/bin/python
import sys
import re
ret = 1
try:
    with open(sys.argv[1]) as msg:
      res = re.match("^fix gh-[0-9]+.*$", msg.readline())
      if res != None: 
          ret = 0
except:
    pass
if (ret != 0):
    print("Wrong commit message. Example: 'fix gh-1234 foo bar'")
sys.exit(ret)

The problem is that the Git Tower does not seem to contain any arguments inside argv. How to solve this so that I can use Git both from the command line and in the graphical interface, for example Git Tower?

+4
source share
1 answer

Think about it with the Tower Support Team.

In my example, I could not capture the argument (i.e. #!/usr/bin/python), changing it to #!/usr/bin/env bash, I was able to get it. Now $1contains an argument.

Full example:

#!/usr/bin/env bash

# regex to validate in commit msg

    commit_regex='(gh-\d+|merge)'
    error_msg="Aborting commit. Your commit message is missing either a Github Issue ('GH-xxxx') or 'Merge'"

    if ! grep -iqE "$commit_regex" "$1"; then
        echo "$error_msg" >&2
        exit 1
    fi
+2
source

Source: https://habr.com/ru/post/1656228/


All Articles