Last active
August 29, 2015 13:56
-
-
Save cholick/8929352 to your computer and use it in GitHub Desktop.
Pre-commit hook to check for Spock @ignore annotation
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
# Script to initially setup hook globally | |
# For existing repositories, re-run "git init" | |
git config --global init.templatedir '~/.git_template' | |
mkdir -p ~/.git_template/hooks | |
tee > ~/.git_template/hooks/pre-commit << 'EOF' | |
git stash -q --keep-index | |
red=$(tput setaf 1) | |
textreset=$(tput sgr0) | |
IGNORE=`grep -rn --include '*.groovy' '@Ignore' .` | |
RESULT=0 | |
if [ `echo $IGNORE | wc -c` -gt 1 ]; then | |
echo "${red}Not committing. Source still contains @Ignore" | |
echo "$IGNORE $textreset" | |
RESULT=1 | |
fi | |
git stash pop -q | |
exit $RESULT | |
EOF | |
chmod +x ~/.git_template/hooks/pre-commit |
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
# Pre-commit hook that rejects when Groovy source contains @Ignore or @IgnoreRest annotations | |
git stash -q --keep-index | |
red=$(tput setaf 1) | |
textreset=$(tput sgr0) | |
IGNORE=`grep -rn --include '*.groovy' '@Ignore' .` | |
RESULT=0 | |
if [ `echo $IGNORE | wc -c` -gt 1 ]; then | |
echo "${red}Not committing. Source still contains @Ignore" | |
echo "$IGNORE $textreset" | |
RESULT=1 | |
fi | |
git stash pop -q | |
exit $RESULT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works great for me. I ran the init.sh script locally which did create the file in in ~/.git_templates/... but I'm not sure how that will work? I had to copy the file into my existing $repo/.git/hooks dir and it worked great.