Files
pre-commit/pre_commit/resources/hook-tmpl
2017-09-05 09:29:18 -07:00

74 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# This is a randomish md5 to identify this script
# 138fd403232d2ddd5efb44317e38bf03
pushd `dirname $0` > /dev/null
HERE=`pwd`
popd > /dev/null
retv=0
args=""
ENV_PYTHON='{sys_executable}'
SKIP_ON_MISSING_CONF={skip_on_missing_conf}
which pre-commit >& /dev/null
WHICH_RETV=$?
"$ENV_PYTHON" -c 'import pre_commit.main' >& /dev/null
ENV_PYTHON_RETV=$?
python -c 'import pre_commit.main' >& /dev/null
PYTHON_RETV=$?
if ((
(WHICH_RETV != 0) &&
(ENV_PYTHON_RETV != 0) &&
(PYTHON_RETV != 0)
)); then
echo '`{hook_type}` not found. Did you forget to activate your virtualenv?'
exit 1
fi
# Run the legacy pre-commit if it exists
if [ -x "$HERE"/{hook_type}.legacy ]; then
"$HERE"/{hook_type}.legacy
if [ $? -ne 0 ]; then
retv=1
fi
fi
CONF_FILE="$(git rev-parse --show-toplevel)/{config_file}"
if [ ! -f $CONF_FILE ]; then
if [ $SKIP_ON_MISSING_CONF = true ] || [ ! -z $PRE_COMMIT_ALLOW_NO_CONFIG ]; then
echo '`{config_file}` config file not found. Skipping `pre-commit`.'
exit $retv
else
echo 'No {config_file} file was found'
echo '- To temporarily silence this, run `PRE_COMMIT_ALLOW_NO_CONFIG=1 git ...`'
echo '- To permanently silence this, install pre-commit with the `--allow-missing-config` option'
echo '- To uninstall pre-commit run `pre-commit uninstall`'
exit 1
fi
fi
{hook_specific}
# Run pre-commit
if ((WHICH_RETV == 0)); then
pre-commit run $args --config {config_file}
PRE_COMMIT_RETV=$?
elif ((ENV_PYTHON_RETV == 0)); then
"$ENV_PYTHON" -m pre_commit.main run $args
PRE_COMMIT_RETV=$?
else
python -m pre_commit.main run $args
PRE_COMMIT_RETV=$?
fi
if ((PRE_COMMIT_RETV != 0)); then
retv=1
fi
exit $retv