[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

SVN Hooks to require log message, limit size and file type

From: David Xie <ddxie.cn_at_gmail.com>
Date: Wed, 12 Jan 2011 09:46:58 +0800

Hello,

I am looking for a hook to require log message when commit. I succeded to do
it.

At the same time, I want to limit size less than 10MB and forbid .zip .7z
.rar file type.
I found some hooks from internet, tried multi times but all failed. I could
always commit big than 10M files and zip files. I struggled two days but
could not resolve it.

I post my pre-commit at the end.
RHEL 5.3
SVN 1.6.15
Apache 2.2.14
Java 1.6.0_17

Would someone give me some help? Great thanks!

Regards,
David

pre-commit :
#!/bin/sh
REPOS="$1"
TXN="$2"
MAX_SIZE=10240000
MIN_LOG=10
FILTER='\.(zip|rar|o|obj|tar|gz)$'
SVNLOOK=/local/svnroot/subversion/bin/svnlook
# Make sure that the log message contains some text.
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c)
if [ "$LOGMSG" -lt $MIN_LOG ]
then
echo -e "Please enter at least 10 characters for log message. Questions,
contact David" >&2
exit 1
fi

files=$($SVNLOOK changed -t $TXN $REPOS |awk '{print $2}')
for f in $files
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)" >&2
exit 1
fi

done

#All checks passed, so allow the commit.
exit 0
Received on 2011-01-12 02:47:40 CET

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.