From da1e6d4c84de6ded63e6529a9658c7102fb40f47 Mon Sep 17 00:00:00 2001 From: Jonathan Yu Date: Mon, 24 May 2021 13:21:28 -0700 Subject: [PATCH] chore: ensure Husky script runs under bash (#71) --- .husky/pre-commit | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.husky/pre-commit b/.husky/pre-commit index 40f26b5..d3ebcc4 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,19 @@ #!/usr/bin/env bash +# The ./_/husky.sh script always runs this script using "sh" in order +# to try to capture the exit code. This means that bash-isms can cause +# an error message. Some distros, such as Arch, use bash for /bin/sh, +# so do not experience this problem, but this is non-standard and +# Debian-based distributions (including Ubuntu) use dash for /bin/sh. +# +# We work around this by detecting whether we are running under Bash, +# by looking for the BASH environment variable, and replacing the +# current script with a version under Bash by using exec. For details, +# see https://github.com/typicode/husky/issues/971. +if [ -z "${BASH:-}" ]; then + exec bash "$0" "$@" +fi + source "$(dirname "$0")/_/husky.sh" set -euo pipefail