Skip to content

Instantly share code, notes, and snippets.

@javiergarval
Forked from arnobroekhof/pre-commit
Created April 20, 2021 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javiergarval/e6cbd5965bffb6377e20834730e2a64b to your computer and use it in GitHub Desktop.
Save javiergarval/e6cbd5965bffb6377e20834730e2a64b to your computer and use it in GitHub Desktop.
Maven pre commit hook
#!/bin/bash
# save the file as <git_directory>/.git/hooks/pre-commit
echo "Running Maven clean test for errors"
# retrieving current working directory
CWD=`pwd`
MAIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# go to main project dir
cd $MAIN_DIR/../../
# running maven clean test
mvn clean test
if [ $? -ne 0 ]; then
"Error while testing the code"
# go back to current working dir
cd $CWD
exit 1
fi
# go back to current working dir
cd $CWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment