diff options
author | Benjamin C Meyer <ben@meyerhome.net> | 2010-03-16 21:25:05 -0400 |
---|---|---|
committer | Benjamin C Meyer <ben@meyerhome.net> | 2010-03-17 01:56:22 -0400 |
commit | 25725bc30bbf24919e82a9e2ecbe055ba1ab3061 (patch) | |
tree | d369bafa6f5ebe03de785968c90fd528dc86807d | |
parent | 87b670fb4bdf465cf2fe68d7dce0cc0db47f7110 (diff) | |
download | git-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>
-rwxr-xr-x | contrib/pre-commit/bash_syntax | 22 |
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 |