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

problem with precommit hook

From: Laurent Michenaud <lmichenaud_at_adeuza.fr>
Date: 2007-09-14 12:32:01 CEST

Hi

I've written a hook that checks the .java files with checkstyle.

Everythings is ok when files already exists in Svn.
But on file add, the check is always done on the first content
sent. What i mean is that when i commit for the first time a file
with check errors, then i correct the errors and recommits but
it doesnot work because the check is always on the first content
i sent.

Here is my hook :
 
 REPOS="$1"
TXN="$2"

SVNLOOK=/appli/subversion-1.3.2/bin/svnlook
JAVA=/appli/java5/bin/java
CHECKSTYLE=/appli/checkstyle/checkstyle-all-4.3.jar
TMPDIR=/tmp/subversion/$TXN
REPORT=/tmp/subversion/$TXN/report
CHECKSTYLE_CONFIG=/appli/checkstyle/checkstyle.conf.xml

# Run checkstyle on java files
CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS" | grep -v "^D" |\
awk '{print $2}'`
mkdir -p $TMPDIR
X=0
for LINE in $CHANGED ; do
FILE=`echo $LINE | egrep \\.java$`
if [ -n "$FILE" ] ; then

$SVNLOOK cat $REPOS --transaction $TXN $FILE > $TMPDIR/tmpfile.java
$JAVA -jar $CHECKSTYLE -c $CHECKSTYLE_CONFIG $TMPDIR/tmpfile.java \
> $TMPDIR/tmpfile.checkstyle

X=$(($X + $?))
cat $TMPDIR/tmpfile.checkstyle | \
grep -v "^Starting audit...$\|^Audit done.$" |\
sed -e "s@$TMPDIR/tmpfile.java@$FILE@" >> $REPORT
fi
done

if [ $X -ne 0 ] ; then
cat $REPORT > /dev/stderr
rm -Rf $TMPDIR
exit 1
fi
rm -Rf $TMPDIR

# All checks passed, so allow the commit.
exit 0
 
 
 
Thanks.
Received on Fri Sep 14 12:28:41 2007

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.