git.hooks.pre-commit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zg2pro-formatter-plugin Show documentation
Show all versions of zg2pro-formatter-plugin Show documentation
This maven plugin enabled strong rules for formatting your java project, without relying on the IDEs formatting features
The newest version!
#! /bin/bash
if ! [ -x "$(command -v git)" ]; then
echo 'Error: git is not installed in path.' >&2
exit 1
fi
if ! [ -x "$(command -v mvn)" ]; then
echo 'Error: maven is not installed in path.' >&2
exit 1
fi
echo running validation and formatting
#If -v is specified twice, then also show the changes in the working tree that have not yet been staged
before=`git status -v -v`
echo "format before the commit is stored"
# pattern will always be found with mvn validate, it cant fail even if compilation fails,
# this helps waiting for mvn process to be done before going to git diffs
mvn clean validate | grep -e 'BUILD SUCCESS'
echo "format re-applied"
after=`git status -v -v`
echo "format after reformat compared to new format"
if [ "$before" != "$after" ]; then
echo "\n"
echo "COMMIT REJECTED Found unformatted code. Please check before commiting and try again"
exit 1
fi