3 ## Originally from http://projects.puppetlabs.com/projects/1/wiki/Puppet_Version_Control
7 error_msg
=$
(mktemp
/tmp
/error_msg.XXXXXX
)
9 if git rev-parse
--quiet --verify HEAD
> /dev
/null
13 # Initial commit: diff against an empty tree object
14 against
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
17 # Get list of new/modified manifest and template files to check (in git index)
18 for indexfile
in $
(git diff-index
--diff-filter=AM
--name-only --cached $against |
egrep '\.(pp|erb)')
20 # Don't check empty files
21 if [ $
(git cat-file
-s :0:$indexfile) -gt 0 ]
25 # Check puppet manifest syntax
26 # Puppet 2.7.20 or newer
27 git cat-file blob
:0:$indexfile | puppet parser validate
> $error_msg ;;
29 # Check ERB template syntax
30 # -P : ignore lines which start with "%"
31 git cat-file blob
:0:$indexfile | erb
-P -x -T - | ruby
-c 2> $error_msg > /dev
/null
;;
35 echo -n "$indexfile: "
37 syntax_errors
=`expr $syntax_errors + 1`
44 if [ "$syntax_errors" -ne 0 ]
46 echo "Error: $syntax_errors syntax errors found, aborting commit."