Git commit hook - 如何使用commit-msg钩子检查消息中的字符串?

lol*_*lol 2 git bash perl hook

我需要创建一个commit-msg钩子来检查提交消息中是否包含"app.asana".我搜索了一些参考资料和文档,我知道我需要使用commit-msg.我必须使用Perl或Bash来制作它.

有没有人知道这个或某个地方我可以看看更多的例子来学习如何做到这一点?

谢谢.

lol*_*lol 8

我找到了一个问题的答案.如果它可以帮助某人......

我刚创建了一个包含的commit-msg文件.git/hooks

#!/bin/sh

test -n "$(grep 'app.asana.com/' ${1})" || {
        echo >&2 "ERROR: Commit message is missing Asana's task link.\n\nPlease append the Asana's task link relative to this commit into the commit message."
        exit 1
}
Run Code Online (Sandbox Code Playgroud)

每个用户都需要有一个commit-msg文件.git/hooks.然后,作为一个解决方案,我添加commit-msg到项目文件夹(所以我可以拉这个)与另一个名为commit-msg-hook.sh包含的文件:

#!/bin/sh

cp commit-msg .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
echo "\nThe commit-msg hook was added to git hooks"
Run Code Online (Sandbox Code Playgroud)

我欢迎任何建议,以改善我所做的.谢谢.