3 if git rev-parse --verify HEAD &>/dev/null; then
6 # Initial commit: diff against an empty tree object
7 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
10 check_puppet_manifest () {
13 local pp=${workdir}/${file}
14 mkdir -p $(dirname ${pp})
15 git cat-file blob :0:${file} | sed 's/^import .*/#&/' >${pp}
16 trap "rm -f ${pp}" RETURN
18 local output=$(puppet apply --noop ${pp} 2>&1)
19 if [ $? -ne 0 ] || [ -n "${output}" ]; then
20 echo '** Syntax check failed:' >&2
25 # Check manifests for exactly one class or define per file.
27 modules/*/manifests/*)
28 if [[ "$(egrep -c '^(class|define) ' ${file})" != "1" ]]; then
29 echo "** Multiple class/defines:" >&2
30 egrep -n '^(class|define) ' ${file} >&2
37 manifests/site.pp|modules/*/manifests/*) ;;
41 if [ -x /usr/bin/pcregrep ]; then
43 # grep -nPT would be nice. grep -P seems broken on gudeploy01.
44 # Patterns checked for are (in this order):
46 # - SPACE followed by TAB
47 # - TAB followed by SPACE
48 # - non-leading TAB (but allow around '#' comment leader)
49 # - trailing whitespace
50 pcregrep -n -e '^ ' -e ' \t' -e '\t ' -e '[^\t#]\t+(?!#)' -e '\s+$' ${pp}
52 if [[ $(wc -l <${pp}) > $(cat -s ${pp}|wc -l) ]]; then
53 wsfail+="Excess blank line(s). 'cat -s' is your friend."
55 if [[ -n "${wsfail}" ]]; then
56 echo '** Bad whitespace (see Manifest Standards):' >&2
61 echo "Missing pcregrep: apt-get install pcregrep" >&2
65 manifests/site.pp|modules/*/manifests/*)
66 puppet-lint --no-hard_tabs-check --no-80chars-check ${pp} >&2 | uniq
76 # Check a Puppet template.
78 check_puppet_template () {
81 # Beware of 'Syntax OK' message on success.
82 local output=$((git cat-file blob :0:${file}|erb -x -P -T -|ruby -c >/dev/null) 2>&1)
83 if [[ $? -ne 0 || -n "${output}" ]]; then
84 echo '** Syntax check failed:' >&2
92 readonly failed=$(mktemp ${TMPDIR:-/tmp}/git.puppet.pre-commit.XXXXXXXXXX)
93 readonly missing=$(mktemp ${TMPDIR:-/tmp}/git.puppet.pre-commit.XXXXXXXXXX)
94 readonly parse=$(mktemp ${TMPDIR:-/tmp}/git.puppet.pre-commit.XXXXXXXXXX)
95 readonly retest=$(mktemp ${TMPDIR:-/tmp}/git.puppet.pre-commit.XXXXXXXXXX)
96 readonly workdir=$(mktemp -d ${TMPDIR:-/tmp}/git.puppet.pre-commit.XXXXXXXXXX)
97 trap "rm -f ${failed} ${missing} ${parse} ${retest}; rm -rf ${workdir}" EXIT
101 for file in $(git diff-index --name-only --diff-filter=AM --cached ${against}); do
107 output=$(check_puppet_manifest ${file} 2>&1); rc=$?;;
111 modules/*/manifests/*)
113 # FIXME: doing this so the whitespace check happens
114 *.pp) output=$(check_puppet_manifest ${file} 2>&1); rc=$?;;
117 modules/*/templates/*)
118 output=$(check_puppet_template ${file} 2>&1); rc=$?;;
124 if [[ ${rc} -ne 0 || -n "${output}" ]]; then
125 echo "** ${file}" >&2
127 if [[ ${file} != *.pp ]]; then
129 # puppet-lint warnings are acceptable.
130 elif [[ -n "$(egrep -v '^WARNING: ' <<<${output})" ]]; then
138 if [ "$error" -ne 0 ]; then
139 echo "** Please correct the above errors." >&2
143 if [ "$warning" -ne 0 ]; then