Created
January 2, 2014 23:05
-
-
Save tsaavik/8228894 to your computer and use it in GitHub Desktop.
Puppet parser/lint git pre-commit hook script.
Improves on versions I've seen around the net
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/bash | |
declare -a files | |
IFS=$'\n' | |
# Check for puppet lint | |
if requires=$(which puppet puppet-lint git 2>&1) ;then | |
: #We have puppet-lint and git, good | |
else | |
echo -e "Error, missing required item(s) from path.\n Requires: git puppet-lint\n\nFound:\n${requires}" | |
exit 1 | |
fi | |
files=$(git diff --cached --name-only --diff-filter=ACM ) | |
for file in ${files[@]} ;do | |
if [[ ${file} =~ \.*.pp$ ]] ;then | |
if puppet parser validate ${file} ;then | |
: | |
else | |
echo "puppet-lint failed on ${file}, exiting, not commiting to git" | |
exit 1 | |
fi | |
if puppet-lint "${file}" ;then | |
echo "${file} had no ERRORS, Check for warnings..... Auto continuing in 5 seconds, ctrl-c to abort" | |
sleep 5 | |
else | |
echo "puppet-lint failed, exiting, not commiting" | |
exit 1 | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment