SVN限制上传文件类型和强制提交信息

marksugar
2016-06-16 / 0 评论 / 3,856 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2016年06月16日,已超过1950天没有更新,若内容或图片失效,请留言反馈。

pre-commit需要700权限,放置hooks即可
pre-commit

#!/bin/bash
#site www.linuxea.com
#blog www.linuxea.com
#by mark
#####################################
REPOS="$1"
TXN="$2"
MAX_SIZE=524280 #限制上传文件大小file 5M
FILTER='\.(zip|rar|o|ibj|tar|gz)$' #限制扩展名

SVNLOOK=/usr/bin/svnlook
#LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c`
LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" |wc -c`
#如果提交的信息小于9则不让提交
if [ "$LOGMSG" -lt 9 ];
then
        echo -e "error: can not be empty, you must enter at least 8 characters" 1>&2
exit 1
fi
files=$($SVNLOOK changed -t $TXN $REPOS |cut -d "" -f 4-)
#echo "$files" >&2
#echo "$r" >&2
#exit 1

rc=0
echo "$files"|while read f;
do
#check file type
if echo $f |tr A-Z a-z|grep -Eq $FILTER;
then
        echo "File $f is not allow ($FILTER) file" >&2
        exit 1;
fi

#check file size
filesize=`$SVNLOOK cat -t "$TXN" "$REPOS" "$f" |wc -c`
if [ "$filesize" -gt "$MAX_SIZE" ]; #比对上传文件大小
then
        echo "File $f is too large(must <=$MAX_SIZE) B" >&2
        exit 1;
fi
done
#ALL checks passed. so allow the commit.
if [ $? -eq 1 ];
then
exit 1
else
exit 0
fi

svn1.png
svn2.png

0

评论 (0)

取消