aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2020-04-12 00:36:39 +0200
committerKate Ward <kate.ward@forestent.com>2020-04-12 00:36:39 +0200
commit42dfe33e61df4fdeae8da0e02ea97a00115a5afb (patch)
treeb92f41f72ee2ff0770eb73921c263026a0ce54f1
parent6d54e984aabc59f204db8d6b51a50bc8dae929bd (diff)
downloadshflags-42dfe33e61df4fdeae8da0e02ea97a00115a5afb.tar.gz
Fixed bug that allowed bad commit to succeed.
-rwxr-xr-x.githooks/generic9
-rwxr-xr-x.githooks/pre-commit.shellcheck12
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}