mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix specify config file not work while installing
Via `pre-commit install -c .other-config.yaml`
This commit is contained in:
parent
8b14c6c5ae
commit
f9a849abcc
5 changed files with 11 additions and 8 deletions
|
|
@ -71,6 +71,7 @@ def install(
|
||||||
sys_executable=sys.executable,
|
sys_executable=sys.executable,
|
||||||
hook_type=hook_type,
|
hook_type=hook_type,
|
||||||
hook_specific=hook_specific_contents,
|
hook_specific=hook_specific_contents,
|
||||||
|
config_file=runner.config_file,
|
||||||
skip_on_missing_conf=skip_on_missing_conf,
|
skip_on_missing_conf=skip_on_missing_conf,
|
||||||
)
|
)
|
||||||
pre_commit_file_obj.write(contents)
|
pre_commit_file_obj.write(contents)
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
args="run --hook-stage=commit-msg --commit-msg-filename=$1"
|
args="--hook-stage=commit-msg --commit-msg-filename=$1"
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,13 @@ if [ -x "$HERE"/{hook_type}.legacy ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CONF_FILE=$(git rev-parse --show-toplevel)"/.pre-commit-config.yaml"
|
CONF_FILE=$(git rev-parse --show-toplevel)"/{config_file}"
|
||||||
if [ ! -f $CONF_FILE ]; then
|
if [ ! -f $CONF_FILE ]; then
|
||||||
if [ $SKIP_ON_MISSING_CONF = true ] || [ ! -z $PRE_COMMIT_ALLOW_NO_CONFIG ]; 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`.'
|
echo '`{config_file}` config file not found. Skipping `pre-commit`.'
|
||||||
exit $retv
|
exit $retv
|
||||||
else
|
else
|
||||||
echo 'No .pre-commit-config.yaml file was found'
|
echo 'No {config_file} file was found'
|
||||||
echo '- To temporarily silence this, run `PRE_COMMIT_ALLOW_NO_CONFIG=1 git ...`'
|
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 permanently silence this, install pre-commit with the `--allow-missing-config` option'
|
||||||
echo '- To uninstall pre-commit run `pre-commit uninstall`'
|
echo '- To uninstall pre-commit run `pre-commit uninstall`'
|
||||||
|
|
@ -56,7 +56,7 @@ fi
|
||||||
|
|
||||||
# Run pre-commit
|
# Run pre-commit
|
||||||
if ((WHICH_RETV == 0)); then
|
if ((WHICH_RETV == 0)); then
|
||||||
pre-commit $args
|
pre-commit run $args -c {config_file}
|
||||||
PRE_COMMIT_RETV=$?
|
PRE_COMMIT_RETV=$?
|
||||||
elif ((ENV_PYTHON_RETV == 0)); then
|
elif ((ENV_PYTHON_RETV == 0)); then
|
||||||
"$ENV_PYTHON" -m pre_commit.main $args
|
"$ENV_PYTHON" -m pre_commit.main $args
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ do
|
||||||
# Check that the ancestor has at least one parent
|
# Check that the ancestor has at least one parent
|
||||||
git rev-list --max-parents=0 "$local_sha" | grep "$first_ancestor" > /dev/null
|
git rev-list --max-parents=0 "$local_sha" | grep "$first_ancestor" > /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
args="run --all-files"
|
args="--all-files"
|
||||||
else
|
else
|
||||||
source=$(git rev-parse "$first_ancestor"^)
|
source=$(git rev-parse "$first_ancestor"^)
|
||||||
args="run --origin $local_sha --source $source"
|
args="--origin $local_sha --source $source"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
args="run --origin $local_sha --source $remote_sha"
|
args="--origin $local_sha --source $remote_sha"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ def test_install_pre_commit(tempdir_factory):
|
||||||
sys_executable=sys.executable,
|
sys_executable=sys.executable,
|
||||||
hook_type='pre-commit',
|
hook_type='pre-commit',
|
||||||
hook_specific='',
|
hook_specific='',
|
||||||
|
config_file=runner.config_file,
|
||||||
skip_on_missing_conf='false',
|
skip_on_missing_conf='false',
|
||||||
)
|
)
|
||||||
assert pre_commit_contents == expected_contents
|
assert pre_commit_contents == expected_contents
|
||||||
|
|
@ -72,6 +73,7 @@ def test_install_pre_commit(tempdir_factory):
|
||||||
sys_executable=sys.executable,
|
sys_executable=sys.executable,
|
||||||
hook_type='pre-push',
|
hook_type='pre-push',
|
||||||
hook_specific=pre_push_template_contents,
|
hook_specific=pre_push_template_contents,
|
||||||
|
config_file=runner.config_file,
|
||||||
skip_on_missing_conf='false',
|
skip_on_missing_conf='false',
|
||||||
)
|
)
|
||||||
assert pre_push_contents == expected_contents
|
assert pre_push_contents == expected_contents
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue