我建议不要使用链式更新挂钩,而是使用Gitolite V3 提供的VREFS 。你可以在这里看到它的所有论点。
由于 VREF 基本上就像一个钩子,你可以像在这个脚本中一样,获取每个提交的日志消息:git update
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
cwhsu在评论中提到: