aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-04-05 21:00:09 -0300
committerSilvio Rhatto <rhatto@riseup.net>2014-04-05 21:00:09 -0300
commit2764f10a64435e88c5ed2dda22eea33ad1a3f93f (patch)
tree98baa3acb800da8315c3dec6ea7af7d26a679542
parent01721111951f32c4761ffa846b81ff029f455c14 (diff)
downloadgit-2764f10a64435e88c5ed2dda22eea33ad1a3f93f.tar.gz
git-2764f10a64435e88c5ed2dda22eea33ad1a3f93f.tar.bz2
Adding git-hooks configuration
-rwxr-xr-xgit_hooks.dot.link/pre-commit/puppet50
-rw-r--r--gitconfig.dot.link5
2 files changed, 54 insertions, 1 deletions
diff --git a/git_hooks.dot.link/pre-commit/puppet b/git_hooks.dot.link/pre-commit/puppet
new file mode 100755
index 0000000..986ca4a
--- /dev/null
+++ b/git_hooks.dot.link/pre-commit/puppet
@@ -0,0 +1,50 @@
+#!/bin/sh
+# Git Pre-Commit Hook from http://projects.puppetlabs.com/projects/1/wiki/puppet_version_control
+#
+# Alternatives: https://gist.github.com/jumanjiman/3275053
+# http://www.snijders-it.nl/2011/12/example-puppet-27-git-pre-commit-script.html
+
+syntax_errors=0
+error_msg=$(mktemp /tmp/error_msg.XXXXXX)
+
+if git rev-parse --quiet --verify HEAD > /dev/null
+then
+ against=HEAD
+else
+ # Initial commit: diff against an empty tree object
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+# Get list of new/modified manifest and template files to check (in git index)
+for indexfile in `git diff-index --diff-filter=AM --name-only --cached $against | egrep '\.(pp|erb)'`
+do
+ # Don't check empty files
+ if [ `git cat-file -s :0:$indexfile` -gt 0 ]
+ then
+ case $indexfile in
+ *.pp )
+ # Check puppet manifest syntax
+ #git cat-file blob :0:$indexfile | puppet --color=false --parseonly --ignoreimport > $error_msg ;;
+ # Updated for 2.7.x
+ puppet parser validate $indexfile > $error_msg ;;
+ *.erb )
+ # Check ERB template syntax
+ # -P : ignore lines which start with "%"
+ git cat-file blob :0:$indexfile | erb -P -x -T - | ruby -c 2> $error_msg > /dev/null ;;
+ esac
+ if [ "$?" -ne 0 ]
+ then
+ echo -n "$indexfile: "
+ cat $error_msg
+ syntax_errors=`expr $syntax_errors + 1`
+ fi
+ fi
+done
+
+rm -f $error_msg
+
+if [ "$syntax_errors" -ne 0 ]
+then
+ echo "Error: $syntax_errors syntax errors found, aborting commit."
+ exit 1
+fi
diff --git a/gitconfig.dot.link b/gitconfig.dot.link
index 38f5e96..2c332de 100644
--- a/gitconfig.dot.link
+++ b/gitconfig.dot.link
@@ -8,4 +8,7 @@
path = .custom/gitconfig
[push]
- default = matching
+ default = matching
+
+[hooks]
+ global = ~/apps/scripts/misc/git-hooks/contrib/ ~/.git_hooks