我在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似乎没有在argv内部包含任何争论。如何解决这一问题,我可以在命令行中使用git,就像在GUI中一样,比如Git?
发布于 2016-10-11 14:02:14
在塔支援小组的帮助下解决了这个问题。
在我的例子中,我无法抓住这个论点(即:#!/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
fihttps://stackoverflow.com/questions/39770937
复制相似问题