繁体   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