Skip to content

Commit eb7c9f4

Browse files
committed
Add test for custom config installation
1 parent f9a849a commit eb7c9f4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pre_commit/resources/hook-tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if [ -x "$HERE"/{hook_type}.legacy ]; then
3838
fi
3939
fi
4040

41-
CONF_FILE=$(git rev-parse --show-toplevel)"/{config_file}"
41+
CONF_FILE="$(git rev-parse --show-toplevel)/{config_file}"
4242
if [ ! -f $CONF_FILE ]; then
4343
if [ $SKIP_ON_MISSING_CONF = true ] || [ ! -z $PRE_COMMIT_ALLOW_NO_CONFIG ]; then
4444
echo '`{config_file}` config file not found. Skipping `pre-commit`.'
@@ -56,7 +56,7 @@ fi
5656

5757
# Run pre-commit
5858
if ((WHICH_RETV == 0)); then
59-
pre-commit run $args -c {config_file}
59+
pre-commit run $args --config {config_file}
6060
PRE_COMMIT_RETV=$?
6161
elif ((ENV_PYTHON_RETV == 0)); then
6262
"$ENV_PYTHON" -m pre_commit.main $args

tests/commands/install_uninstall_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ def test_install_pre_commit_and_run(tempdir_factory):
162162
assert NORMAL_PRE_COMMIT_RUN.match(output)
163163

164164

165+
def test_install_pre_commit_and_run_custom_path(tempdir_factory):
166+
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
167+
with cwd(path):
168+
cmd_output('git', 'mv', C.CONFIG_FILE, 'custom-config.yaml')
169+
cmd_output('git', 'commit', '-m', 'move pre-commit config')
170+
assert install(Runner(path, 'custom-config.yaml')) == 0
171+
172+
ret, output = _get_commit_output(tempdir_factory)
173+
assert ret == 0
174+
assert NORMAL_PRE_COMMIT_RUN.match(output)
175+
176+
165177
def test_install_in_submodule_and_run(tempdir_factory):
166178
src_path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
167179
parent_path = git_dir(tempdir_factory)

0 commit comments

Comments
 (0)