Created
January 23, 2015 11:44
-
-
Save oneandoneis2/15170aae2c9c3b1294fa to your computer and use it in GitHub Desktop.
Save as .git/hooks/pre-commit in your puppet repo to ensure valid syntax in .pp and .erb files
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 | |
# Override error checking so we can commit WIP or whatever with | |
# JFDI=1 git commit .... | |
if [ "0$JFDI" -eq 1 ]; then | |
exit 0 | |
fi | |
# Redirect output to stderr. | |
exec 1>&2 | |
errors=0 | |
# Check any puppet files we're about to commit | |
for puppet_file in $(git diff-index --cached HEAD --name-only | grep '\.pp'); do | |
puppet parser validate --color true --render-as s $puppet_file || errors=1 | |
done | |
# Check any templates we're about to commit | |
for template_file in $(git diff-index --cached HEAD --name-only | grep '\.erb'); do | |
erb -x -T '-' $template_file | ruby -c > /dev/null || errors=1 | |
done | |
if [ "$errors" -eq 1 ]; then | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment