From: Benjamin C Meyer Date: Wed, 17 Mar 2010 01:25:05 +0000 (-0400) Subject: Add a pre-commit hook that checks bash files for syntax errors X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=25725bc30bbf24919e82a9e2ecbe055ba1ab3061;p=git-hooks.git Add a pre-commit hook that checks bash files for syntax errors Signed-off-by: Benjamin C Meyer --- 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