Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsaavik/8228894 to your computer and use it in GitHub Desktop.
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
#!/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