3 GIT_DIR
=$
(git rev-parse
--git-dir)
5 if [ -z "$GIT_DIR" ]; then
6 echo >&2 "Not in a git checkout"
10 cat << 'EOF' > $GIT_DIR/hooks
/pre-commit.tmp$$
13 # based on http://projects.puppetlabs.com/projects/1/wiki/Puppet_Version_Control
16 error_msg
=$
(mktemp
/tmp
/error_msg.XXXXXX
)
18 if git rev-parse
--quiet --verify HEAD
> /dev
/null
22 # Initial commit: diff against an empty tree object
23 against
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
26 # Get list of new/modified manifest and template files to check (in git index)
27 for indexfile
in `git diff-index --diff-filter=AM --name-only --cached $against | egrep '\.(pp|erb)'`
29 # Don't check empty files
30 if [ `git cat-file -s :0:$indexfile` -gt 0 ]
34 # Check puppet manifest syntax
35 # Puppet 2.7.20 or newer
36 git cat-file blob
:0:$indexfile | puppet parser validate
> $error_msg ;;
38 # Check ERB template syntax
39 # -P : ignore lines which start with "%"
40 git cat-file blob
:0:$indexfile | erb
-P -x -T - | ruby
-c 2> $error_msg > /dev
/null
;;
44 echo -n "$indexfile: "
46 syntax_errors
=`expr $syntax_errors + 1`
53 if [ "$syntax_errors" -ne 0 ]
55 echo "Error: $syntax_errors syntax errors found, aborting commit."
60 if ! cmp $GIT_DIR/hooks
/pre-commit
$GIT_DIR/hooks
/pre-commit.tmp$$
; then
61 cp $GIT_DIR/hooks
/pre-commit
{,.backup-$
(date +%Y
%m
%d
%H
%M
)}
62 mv $GIT_DIR/hooks
/pre-commit.tmp$$
$GIT_DIR/hooks
/pre-commit
64 chmod ugo
+x
$GIT_DIR/hooks
/pre-commit