Last active
March 15, 2020 13:45
-
-
Save alanhe421/baa359d064b17988bb8cd89a0bbe4c2e to your computer and use it in GitHub Desktop.
checkstyle when pre commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
#!/bin/bash -e cp pre-commit ../../.git/hooks/ chmod +x ../../.git/hooks/pre-commit