Skip to content

Instantly share code, notes, and snippets.

@crazed
Created May 25, 2012 16:59
Show Gist options
  • Save crazed/2789203 to your computer and use it in GitHub Desktop.
Save crazed/2789203 to your computer and use it in GitHub Desktop.
pre-commit hook for puppet syntax validation
#!/usr/bin/env bash
TEMPDIR=`mktemp -d puppet-parser.XXXXXX`
test -n "$TEMPDIR" || exit 1
test -d "$TEMPDIR" || exit 1
git checkout-index --prefix="$TEMPDIR/" -af
changed_manifests=$(git diff --cached --name-only --diff-filter=ACM | grep '.pp$' | xargs -n 1 -I '{}' echo $TEMPDIR/'{}' | tr '\n' ' ')
validate_status=0
if [[ -n $changed_manifests ]]; then
puppet parser validate $changed_manifests
validate_status=$?
fi
test -d "$TEMPDIR" && rm -rf "$TEMPDIR"
exit $validate_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment