簡體   English   中英

如何在Git Tower中獲取Git Commit消息?

[英]How to get the Git Commit message in Git Tower?

我在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)

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

在Tower支持團隊的幫助下計算出來。

在我的例子中,我無法抓住參數(即: #!/usr/bin/python ),將其更改為#!/usr/bin/env bash我能夠得到它。 現在$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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM