一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

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

时间:2016-09-01 编辑:简简单单 来源:一聚教程网

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

#!/bin/bash

#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

热门栏目