Created
June 8, 2011 18:23
-
-
Save Bochenski/1014994 to your computer and use it in GitHub Desktop.
Git pre-commit hook that checks whether changes have been made to a subfolder and if they have runs tests (currently on the play framework but easily adjustable) aborting the commit unless tests pass. Great for continuous integration purposes.
This file contains 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 | |
#A hook script to ensure that all tests are passing before committing | |
#The script tests whether changes have been made in the relevant directory | |
pwd | |
sometext=`git status` | |
if [[ "$sometext" =~ 'play/stocksystem/' ]]; | |
then | |
echo "you changed something in the stocksystem" | |
echo "running tests before proceeding with commit" | |
play auto-test ./play/stocksystem | |
if [ -e play/stocksystem/test-result/result.failed ]; | |
then | |
echo "tests failed, unfortunately I can't accept user input from within a hook" | |
echo "to ask what you want to do about this." | |
echo "so if you want to commit despite failing tests" | |
echo "rerun git commit with the option git commit --no-verify" | |
exit 1 | |
else | |
echo "All tests passed proceeding..." | |
exit 0 | |
fi | |
else | |
echo "No change to stock system detected, proceeding..." | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment