checkstyle when pre commit
#!/bin/bash | |
wd=`pwd` | |
function print(){ | |
echo "===========$*============" | |
} | |
print "Start check style for Java" | |
check_jar_path="$wd/config/checkstyle-8.30-all.jar" | |
check_xml_path="$wd/config/google_checks.xml" | |
rm -f temp | |
is_err=0 | |
for file in `git status --porcelain | sed s/^...// | grep '\.java$'`;do | |
path="$wd/$file" | |
print "Checking file:$path" | |
re=`java -jar $check_jar_path -c $check_xml_path $path >> temp` | |
err=`cat temp | grep "ERROR"` | |
if [[ $err = *"ERROR"* ]];then | |
print "$err" | |
is_err=1 | |
fi | |
done | |
print "Checking completed,God bless you!" | |
rm -f temp | |
if [ $is_err -ne 0 ] | |
then | |
print "Check failed,you should fix it!" | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
#!/bin/bash -e cp pre-commit ../../.git/hooks/ chmod +x ../../.git/hooks/pre-commit