aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorBenjamin C Meyer <ben@meyerhome.net>2010-03-16 21:25:05 -0400
committerBenjamin C Meyer <ben@meyerhome.net>2010-03-17 01:56:22 -0400
commit25725bc30bbf24919e82a9e2ecbe055ba1ab3061 (patch)
treed369bafa6f5ebe03de785968c90fd528dc86807d /contrib
parent87b670fb4bdf465cf2fe68d7dce0cc0db47f7110 (diff)
downloadgit-hooks-25725bc30bbf24919e82a9e2ecbe055ba1ab3061.tar.gz
git-hooks-25725bc30bbf24919e82a9e2ecbe055ba1ab3061.tar.bz2
Add a pre-commit hook that checks bash files for syntax errors
Signed-off-by: Benjamin C Meyer <ben@meyerhome.net>
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/pre-commit/bash_syntax22
1 files changed, 22 insertions, 0 deletions
diff --git a/contrib/pre-commit/bash_syntax b/contrib/pre-commit/bash_syntax
new file mode 100755
index 0000000..7e014e8
--- /dev/null
+++ b/contrib/pre-commit/bash_syntax
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+function test_file {
+ file="${1}"
+ head -n 1 "${file}" | grep 'bash' | grep '^#!/' > /dev/null
+ if [ "$?" -eq 0 ] ; then
+ set -e
+ bash -n "${file}"
+ set +e
+ fi
+}
+
+case "${1}" in
+ --about )
+ echo "Check bash shell scripts for syntax errors."
+ ;;
+ * )
+ for file in `git diff-index --cached --name-only HEAD` ; do
+ test_file "${file}"
+ done
+ ;;
+esac