On Wed, Jan 12, 2011 at 11:46 AM, David Xie <ddxie...@gmail.com> wrote:
> 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 > I'm unfamiliar with unix scripting, but you could try outputting debug messages to a basic text file, so you can trace it through as it runs. Cheers, Daniel B. > 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 > >