diff options
-rwxr-xr-x | .githooks/generic | 9 | ||||
-rwxr-xr-x | .githooks/pre-commit.shellcheck | 12 |
2 files changed, 16 insertions, 5 deletions
diff --git a/.githooks/generic b/.githooks/generic index b1b5cd0..6f903dc 100755 --- a/.githooks/generic +++ b/.githooks/generic @@ -13,7 +13,8 @@ run() { } die() { - echo 'error: hook did not succeed' >&2 + hook=$1 + echo "${hook} hook did not succeed" >&2 exit 1 } @@ -25,10 +26,8 @@ basename=$(basename "$0") for f in $(cd ${githooks} && echo *); do case "${f}" in - pre-commit.*) - # Called by "git commit" with no arguments. - [ "${basename}" = 'pre-commit' ] || continue - run pre-commit "${githooks}/${f}" || die + ${basename}.*) + run ${basename} "${githooks}/${f}" || die "${f}" ;; esac done diff --git a/.githooks/pre-commit.shellcheck b/.githooks/pre-commit.shellcheck index 99a318c..7615d44 100755 --- a/.githooks/pre-commit.shellcheck +++ b/.githooks/pre-commit.shellcheck @@ -7,11 +7,20 @@ # Treat unset variables as an error when performing parameter expansion. set -u +TRUE=0 +FALSE=1 + +die() { + echo "$@" >&2 + exit 1 +} + if ! command -v shellcheck >/dev/null; then echo 'unable to locate shellcheck' >&2 return 0 fi +success=${TRUE} for f in $(git diff --cached --name-only); do cmd=':' case "${f}" in @@ -19,6 +28,9 @@ for f in $(git diff --cached --name-only); do *.sh) cmd="shellcheck ${f}" ;; esac if ! ${cmd}; then + success=${FALSE} echo "shellcheck error for '${f}'" >&2 fi done + +exit ${success} |