gpt4 book ai didi

Git 提交 Hook - 如何使用 commit-msg Hook 检查消息中的字符串?

转载 作者:太空狗 更新时间:2023-10-29 14:27:17 26 4
gpt4 key购买 nike

我需要制作一个 commit-msg Hook 来检查提交消息是否包含“app.asana”。我搜索了一些引用资料和文档,我知道我需要为此使用 commit-msg。我必须使用 Perl 或 Bash 来实现。

有没有人对此有任何线索,或者我可以在某个地方查看更多示例以了解如何做?

谢谢。

最佳答案

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

我刚刚在 .git/hooks 中创建了一个 commit-msg 文件,其中包含

#!/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
}

每个用户都需要在 .git/hooks 中有一个 commit-msg 文件。然后,作为解决方案,我将 commit-msg 添加到项目文件夹(这样我就可以 pull 这个了)和另一个名为 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"

我欢迎任何改进我所做工作的建议。谢谢。

关于Git 提交 Hook - 如何使用 commit-msg Hook 检查消息中的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19272901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com