git服务器钩子设置之限制成员提交代码注释长度
技术  /  管理员 发布于 2年前   535
git代码库服务端做控制限制:限制成员提交代码注释长度
需要用到了GIT的pre-receive钩子,这个钩子会在客户端发起push请求后调用执行,
只有执行通过才能合并进代码库,话不多说直接上代码:
#!/bin/bash
#pre-receive script
#set -x #for debugging
validate_ref()
{
# --- Arguments
oldrev=$(git rev-parse $1)
newrev=$(git rev-parse $2)
refname="$3"
commitList=`git rev-list $oldrev..$newrev`
#echo $commitList
split=($commitList)
for s in ${split[@]}
do
echo "@@@@@@@"
echo "$s"
msg=`git cat-file commit $s | sed '1,/^$/d'`
echo $msg
if [ ${#msg} -lt 15 ];then
echo "!!! Commit message length less than 15"
exit 1
else
echo "bigger than 5"
fi
done
}
fail=""
# Allow dual mode: run from the command line just like the update hook, or
# if no arguments are given then run as a hook script
if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
# Output to the terminal in command line mode - if someone wanted to
# resend an email; they could redirect the output to sendmail
# themselves
PAGER= validate_ref $2 $3 $1
else
while read oldrev newrev refname
do
validate_ref $oldrev $newrev $refname
done
fi
if [ -n "$fail" ]; then
exit $fail
fi
将代码文件命名为pre-receive,并且可执行权限设置为777(注意跨平台文件格式问题)
在git服务器源代码存储的目录(如abc.git),在abc.git目录创建一个新目录custom_hooks
将pre-receive放在custom_hooks目录下,就ok了,gitlab服务器会立刻生效。
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号