【问题标题】:How to get the Git Commit message in Git Tower?如何在 Git Tower 中获取 Git Commit 消息?
【发布时间】:2016-09-29 12:54:27
【问题描述】:

我在 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 中?

【问题讨论】:

  • 这也是 SmartGit 和其他 GUI 工具的问题。
  • 这听起来像是 Git Tower 中的一个错误,因为你的钩子看起来不错。由于they claim that hooks should work(尽管应该将消息打印到stderr),我会就此联系Git Tower Support
  • 检查,已联系支持团队

标签: git githooks git-tower


【解决方案1】:

在 Tower 支持团队的帮助下解决了这个问题。

在我的示例中,我无法通过将其更改为 #!/usr/bin/env bash 来获取参数(即:#!/usr/bin/python)我能够得到它。现在$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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    相关资源
    最近更新 更多