Last active
August 29, 2015 14:07
-
-
Save gsarjeant/eb5b9a52f65f2eb399ef to your computer and use it in GitHub Desktop.
Puppet module git pre-commit hook: no git-stash
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/sh | |
# If we don't have a HEAD, then this is the first commit and we can't do any of this | |
git show > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then exit 0; fi | |
EXITCODE=0 | |
for file in `git diff-index --cached --diff-filter=AM --name-only HEAD` | |
do | |
echo "Validating ${file}..." | |
case "${file##*.}" in | |
"pp") puppet-lint --no-80chars-check ${file} | |
EXITCODE=$((EXITCODE + $?)) | |
puppet parser validate ${file} | |
EXITCODE=$((EXITCODE + $?)) | |
;; | |
"erb") /opt/puppet/bin/erb -P -x -T '-' ${file} | /opt/puppet/bin/ruby -c >/dev/null | |
EXITCODE=$((EXITCODE + $?)) | |
;; | |
esac | |
done | |
if [ $EXITCODE -ne 0 ] | |
then | |
echo | |
echo "################################################################" | |
echo -e "### \033[31mPlease fix the errors above before committing your code.\033[0m ###" | |
echo "################################################################" | |
if [[ -s /tmp/stash.$$ ]] | |
then | |
echo "### ###" | |
echo -e "### \033[31mDid you remember to git add your updated code?\033[0m ###" | |
echo "### ###" | |
echo "################################################################" | |
fi | |
echo | |
fi | |
exit $EXITCODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment