爲了方便管理,svn上傳需要限制文件大小
svn有幾種鉤子,資料一搜一大把,限制上傳文件大小需要用到 pre-commit
在倉庫hooks目錄下有示例配置文件,新建一個名爲 pre-commit 的腳本,內容如下:
#!/bin/bash
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
MAX_SIZE=512000
files=$($SVNLOOK changed -t $TXN $REPOS | awk '{print $2}')
# check check
if [[ $files =~ "project_nuli" ]];then
for f in $files
do
# 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)" >> /dev/stderr
exit 1
fi
done
fi
exit 0
客戶端提交大於500K文件會返回 File $f is too large (must <= $MAX_SIZE)
提交時,強制用戶輸入註釋內容:
vim pre-commit
#!/bin/bash
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
files=$($SVNLOOK changed -t $TXN $REPOS | awk '{print $2}')
for f in $files
do
LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c`
if [ "$LOGMSG" -lt 5 ];then
echo -e "\nLog message cann't be empty! you must input more than 5 chars as comment!." 1>&2
exit 1
fi
done
exit 0