Skip to content

Instantly share code, notes, and snippets.

@cholick
Last active August 29, 2015 13:56
Show Gist options
  • Save cholick/8929352 to your computer and use it in GitHub Desktop.
Save cholick/8929352 to your computer and use it in GitHub Desktop.
Pre-commit hook to check for Spock @ignore annotation
# 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
# 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
@csterwa
Copy link

csterwa commented Feb 13, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment