如何在Git Tower中获取Git提交消息?
我正在githook如何在Git Tower中获取Git提交消息?,git,githooks,git-tower,Git,Githooks,Git Tower,我正在githookcommit 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): p
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 Tower这样的GUI中一样从命令行使用git?在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
这也是SmartGit和其他GUI工具的一个问题。这听起来像Git Tower中的一个bug,因为你的钩子看起来不错。因为(尽管消息应该打印到stderr),我会就此联系。检查,联系支持团队