Skip to content

Commit f9a849a

Browse files
committed
Fix specify config file not work while installing
Via `pre-commit install -c .other-config.yaml`
1 parent 8b14c6c commit f9a849a

5 files changed

Lines changed: 11 additions & 8 deletions

File tree

pre_commit/commands/install_uninstall.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def install(
7171
sys_executable=sys.executable,
7272
hook_type=hook_type,
7373
hook_specific=hook_specific_contents,
74+
config_file=runner.config_file,
7475
skip_on_missing_conf=skip_on_missing_conf,
7576
)
7677
pre_commit_file_obj.write(contents)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
args="run --hook-stage=commit-msg --commit-msg-filename=$1"
1+
args="--hook-stage=commit-msg --commit-msg-filename=$1"

pre_commit/resources/hook-tmpl

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

41-
CONF_FILE=$(git rev-parse --show-toplevel)"/.pre-commit-config.yaml"
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
44-
echo '`.pre-commit-config.yaml` config file not found. Skipping `pre-commit`.'
44+
echo '`{config_file}` config file not found. Skipping `pre-commit`.'
4545
exit $retv
4646
else
47-
echo 'No .pre-commit-config.yaml file was found'
47+
echo 'No {config_file} file was found'
4848
echo '- To temporarily silence this, run `PRE_COMMIT_ALLOW_NO_CONFIG=1 git ...`'
4949
echo '- To permanently silence this, install pre-commit with the `--allow-missing-config` option'
5050
echo '- To uninstall pre-commit run `pre-commit uninstall`'
@@ -56,7 +56,7 @@ fi
5656

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

pre_commit/resources/pre-push-tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ do
99
# Check that the ancestor has at least one parent
1010
git rev-list --max-parents=0 "$local_sha" | grep "$first_ancestor" > /dev/null
1111
if [ $? -ne 0 ]; then
12-
args="run --all-files"
12+
args="--all-files"
1313
else
1414
source=$(git rev-parse "$first_ancestor"^)
15-
args="run --origin $local_sha --source $source"
15+
args="--origin $local_sha --source $source"
1616
fi
1717
fi
1818
else
19-
args="run --origin $local_sha --source $remote_sha"
19+
args="--origin $local_sha --source $remote_sha"
2020
fi
2121
fi
2222
done

tests/commands/install_uninstall_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_install_pre_commit(tempdir_factory):
5757
sys_executable=sys.executable,
5858
hook_type='pre-commit',
5959
hook_specific='',
60+
config_file=runner.config_file,
6061
skip_on_missing_conf='false',
6162
)
6263
assert pre_commit_contents == expected_contents
@@ -72,6 +73,7 @@ def test_install_pre_commit(tempdir_factory):
7273
sys_executable=sys.executable,
7374
hook_type='pre-push',
7475
hook_specific=pre_push_template_contents,
76+
config_file=runner.config_file,
7577
skip_on_missing_conf='false',
7678
)
7779
assert pre_push_contents == expected_contents

0 commit comments

Comments
 (0)