diff --git a/pre_commit/resources/hook-tmpl b/pre_commit/resources/hook-tmpl index 78aa2a83..e18812ff 100644 --- a/pre_commit/resources/hook-tmpl +++ b/pre_commit/resources/hook-tmpl @@ -38,7 +38,7 @@ if [ -x "$HERE"/{hook_type}.legacy ]; then fi fi -CONF_FILE=$(git rev-parse --show-toplevel)"/{config_file}" +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`.' @@ -56,7 +56,7 @@ fi # Run pre-commit if ((WHICH_RETV == 0)); then - pre-commit run $args -c {config_file} + pre-commit run $args --config {config_file} PRE_COMMIT_RETV=$? elif ((ENV_PYTHON_RETV == 0)); then "$ENV_PYTHON" -m pre_commit.main $args diff --git a/tests/commands/install_uninstall_test.py b/tests/commands/install_uninstall_test.py index 357131c5..80e249be 100644 --- a/tests/commands/install_uninstall_test.py +++ b/tests/commands/install_uninstall_test.py @@ -162,6 +162,18 @@ def test_install_pre_commit_and_run(tempdir_factory): assert NORMAL_PRE_COMMIT_RUN.match(output) +def test_install_pre_commit_and_run_custom_path(tempdir_factory): + path = make_consuming_repo(tempdir_factory, 'script_hooks_repo') + with cwd(path): + cmd_output('git', 'mv', C.CONFIG_FILE, 'custom-config.yaml') + cmd_output('git', 'commit', '-m', 'move pre-commit config') + assert install(Runner(path, 'custom-config.yaml')) == 0 + + ret, output = _get_commit_output(tempdir_factory) + assert ret == 0 + assert NORMAL_PRE_COMMIT_RUN.match(output) + + def test_install_in_submodule_and_run(tempdir_factory): src_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo') parent_path = git_dir(tempdir_factory)