awx/pre-commit.sh
Rick Elrod b8ba2feecd Tell Makefile and pre-commit.sh that they are bash
On some systems, /bin/sh is a bash symlink and running it will launch
bash in sh compatibility mode. However, bash-specific syntax will still
work in this mode (for example using == or pipefail).

However, on systems where /bin/sh is a symlink to another shell (think:
Debian-based) they might not have those bashisms.

Set the shell in the Makefile, so that it uses bash (since it is already
depending on bash, even though it is calling it as /bin/sh by default),
and add a shebang to pre-commit.sh for the same reason.

Signed-off-by: Rick Elrod <rick@elrod.me>
2023-07-14 12:06:55 -05:00

33 lines
910 B
Bash
Executable File

#!/usr/bin/env bash
if [ -z $AWX_IGNORE_BLACK ] ; then
python_files_changed=$(git diff --cached --name-only --diff-filter=AM | grep -E '\.py$')
if [ "x$python_files_changed" != "x" ] ; then
black --check $python_files_changed || \
if [ $? != 0 ] ; then
echo 'To fix this, run `make black` to auto-format your code prior to commit, or set AWX_IGNORE_BLACK=1'
exit 1
fi
fi
fi
if [ -z $AWX_IGNORE_USER ] ; then
FAIL=0
export CHANGED_FILES=$(git diff --cached --name-only --diff-filter=AM)
if [ -d ./pre-commit-user ] ; then
for SCRIPT in `find ./pre-commit-user -type f` ; do
if [ -x $SCRIPT ] ; then
echo "Running user pre-commit hook $SCRIPT"
$SCRIPT
if [ $? != 0 ] ; then
echo "User test $SCRIPT failed"
FAIL=1
fi
fi
done
fi
if [ $FAIL == 1 ] ; then
echo "One or more user tests failed, see messages above"
exit 1
fi
fi