running junit test before push on git (with maven)

#!/bin/bash echo "Executing unity test" mvn -f project clean install &> ~/project_log.txt if [[ $? != 0 ]] ; then echo "There is some failed test, pls check the file ~/project_log.txt" exit 1 fi echo "Everything is ok...pushing :p" # ok exit 0
this must be place in the file .git/hooks/pre-push and must have permission 777 to run.
This is just an example using maven and junit test but this script can do anything you want before pushing, if the exit status is != 0 it will not push.
If you work on a team and want to ensure that everyone is running test would be better to put this hook on the remote side https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#Server-Side-Hooks

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.