所有提交消息的git gitolite(v3)预接收挂钩
我试图强制执行一个策略,即当一条提交消息不满足规则时,每次推送都会被拒绝。我已经向开发人员分发了一个钩子,以便他们在本地回购协议中使用它,但我也希望在他们推到原始位置时强制执行 我有两个问题:所有提交消息的git gitolite(v3)预接收挂钩,git,hook,gitolite,githooks,Git,Hook,Gitolite,Githooks,我试图强制执行一个策略,即当一条提交消息不满足规则时,每次推送都会被拒绝。我已经向开发人员分发了一个钩子,以便他们在本地回购协议中使用它,但我也希望在他们推到原始位置时强制执行 我有两个问题: 我应该使用更新钩子还是预接收钩子?(我试图设置update.secondary钩子,但在我看来,它不会被触发,而预接收会被触发) 如何获取推送中包含的每个提交的消息?更具体地说,我希望每个提交消息都有一个特定的“valid”(适合我的需要)前缀。因此,我希望在接受推送消息之前,扫描推送消息中的每个提交,并
谢谢 我建议使用GitoliteV3提供的链接更新钩子,而不是使用链接更新钩子。 你可以看到一切 由于VREF基本上类似于git更新钩子,因此您可以像中一样,使用git log--format=%s-1$commit获取每次提交的日志消息: 对git提交消息强制执行策略的脚本示例:
#!/bin/bash
refname="$1"
oldrev="$2"
newrev="$3"
result=0
# Make sure we handle the situation when the branch does not exist yet
if ! [ "$oldrev" = "0000000000000000000000000000000000000000" ] ; then
excludes=( ^$oldrev )
else
excludes=( $(git for-each-ref --format '^%(refname:short)' refs/heads/) )
fi
# Get the list of incomming commits
commits=`git rev-list $newrev "${excludes[@]}"`
# For every commit in the list
for commit in $commits
do
# check the log message for ticket number
message=`git log --format=%s -1 $commit`
ticket=`echo "$message" | grep -o "^[A-Z]\{2,3\}-[0-9]\+"`
if [ "$ticket" = "" ] ; then
echo "Commit $commit does not start with a ticket number"
result=1
fi
done
exit $result
评论中提到:
- 如果您正试图用shell脚本编写服务器端钩子,您可能想看看“.”
通过使用read-in-shell脚本,我最终获得了
、oldrev
和newrev
refname
- 这也是我想要的
- 这一行“
”,“excludes=(^$oldrev)
”只是表示排除^
你能详细说明你的第二个问题吗?谢谢,我遵循了你的方法,现在一切似乎都正常了。我尝试使用脚本,但我得到了“remote:hooks/pre-receive:10:hooks/pre-receive:Syntax error:”(“意外(预期为“fi”)。我来自这一行”excludes=(^$oldrev)@cwhsu奇怪,我在我的环境中没有收到错误。@VonC我将在其他机器上尝试。我在其他线程中也看到此脚本,没有人对此抱怨。这让我很困惑……无论如何,感谢您的回复。@cwhsu是的,这似乎与您当前的repo的
git状态
有关。我已编辑了答案以添加dou不可靠的引语。