gpt4 book ai didi

gitk 和钩子(Hook)脚本

转载 作者:太空狗 更新时间:2023-10-29 13:46:48 26 4
gpt4 key购买 nike

我想部署一个钩子(Hook)脚本来控制提交消息的格式。为此,我使用了 prepare-commit-msg 脚本。

我想检查提交消息是否以 3 位数字开头。如果是这种情况,脚本返回 0,否则返回 1

它在使用 git 命令时效果很好,但在使用 gitk 时就不行了。当脚本返回 1 时,提交不会中止。我也没有设法显示消息(解释为什么提交将被中止的信息消息)。

有没有办法在 gitk 中使用钩子(Hook)脚本?

谢谢。

PS:我用的是git 1.8.5.3版本

最佳答案

Git client-side hooks 中所述, prepare-commit-msg Hook 在启动提交消息编辑器之前但在创建默认消息之后运行。
所以那不会满足你的要求。最好使用 commit-msg钩子(Hook)。

The commit-msg hook takes one parameter, which again is the path to a temporary file that contains the commit message written by the developer.
If this script exits non-zero, Git aborts the commit process, so you can use it to validate your project state or commit message before allowing a commit to go through.

之后,这取决于您的脚本是如何编写的:参见“How do I prompt the user from within a commit-msg hook?”和this answer特别是:

if you use gitk or git-gui you won't be able to prompt because you get an error on the "exec < /dev/tty" line.

您可以用 hook bash 脚本中定义的函数替换它

function f_askContinue {
local myQuestion=$1

while true; do
read -p "${myQuestion} " -n 1 -r answer
case $answer in
[Yy]* ) printf "\nOK\n"; break;;
[Nn]* ) printf "\nAbandon\n";
exit;;
* ) printf "\nAnswer with Yes or No.\n";;
esac
done
}

f_askContinue "Do you want to continue ?"

(根据您要在控件中实现的逻辑进行调整)

这在 gitk 中可行。

关于gitk 和钩子(Hook)脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36007049/

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