4

我在 gitook 中使用这个脚本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 中?

4

1 回答 1

2

在 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
于 2016-10-11T14:02:14.343 回答