From 25725bc30bbf24919e82a9e2ecbe055ba1ab3061 Mon Sep 17 00:00:00 2001 From: Benjamin C Meyer Date: Tue, 16 Mar 2010 21:25:05 -0400 Subject: Add a pre-commit hook that checks bash files for syntax errors Signed-off-by: Benjamin C Meyer --- contrib/pre-commit/bash_syntax | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 contrib/pre-commit/bash_syntax (limited to 'contrib') 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 -- cgit v1.2.3