mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
Add --allow-missing-config option to install
When no '.pre-commit-config.yaml' file exists while `pre-commit` hooks are enabled, `pre-commit` returns an error and the action is aborted. This is a very common scenario when pre-commit is added later on a project and the user wants to work on a previous branch where the configuration file does not exist. This commits allow the user to optionally install the `pre-commit` hooks with an option to allow a missing configuration and trigger only the legacy pre-commit hooks (if any) when it is missing.
This commit is contained in:
@@ -10,6 +10,7 @@ retv=0
|
||||
args=""
|
||||
|
||||
ENV_PYTHON='{sys_executable}'
|
||||
SKIP_ON_MISSING_CONF={skip_on_missing_conf}
|
||||
|
||||
which pre-commit >& /dev/null
|
||||
WHICH_RETV=$?
|
||||
@@ -37,6 +38,20 @@ if [ -x "$HERE"/{hook_type}.legacy ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
CONF_FILE=$(git rev-parse --show-toplevel)"/.pre-commit-config.yaml"
|
||||
if [ ! -f $CONF_FILE ]; then
|
||||
if [ $SKIP_ON_MISSING_CONF = true ] || [ ! -z $PRE_COMMIT_ALLOW_NO_CONFIG ]; then
|
||||
echo '`.pre-commit-config.yaml` config file not found. Skipping `pre-commit`.'
|
||||
exit $retv
|
||||
else
|
||||
echo 'No .pre-commit-config.yaml file was found\n'\
|
||||
'- To temporarily silence this, run `PRE_COMMIT_ALLOW_NO_CONFIG=1 git ...`\n'\
|
||||
'- To permanently silence this, install pre-commit with the `--allow-missing-config` option\n'\
|
||||
'- To uninstall pre-commit run `pre-commit uninstall`'
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
{pre_push}
|
||||
|
||||
# Run pre-commit
|
||||
|
||||
Reference in New Issue
Block a user