2016-09-29 129 views
4

我在githook commit-msg中使用這個腳本。如何在Git Tower中獲得Git Commit消息?

#!/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) 

問題是Git Tower似乎沒有在argv中包含任何參數。如何解決這個問題,我可以像Git Tower那樣在命令行中使用git?

+0

這是SmartGit和其他GUI工具也是一個問題。 – prabodhprakash

+0

這聽起來像是Git Tower中的一個bug,因爲你的鉤子看起來很好。因爲[他們聲稱鉤子應該工作](https://www.git-tower.com/help/mac/faq-and-tips/faq/hook-scripts)(雖然,信息應該打印到stderr),我請聯繫[Git Tower支持](https://www.git-tower.com/support/contact)。 – Hasturkun

+0

檢查,聯繫支持團隊 –

回答

2

在Tower支持團隊的幫助下找到了這一點。

在我的示例中,我無法通過將其更改爲#!/usr/bin/env bash來獲得參數(即:#!/usr/bin/python)。現在$1包含參數。

完整的示例:

#!/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