Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pre_commit/commands/install_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def install(
sys_executable=sys.executable,
hook_type=hook_type,
hook_specific=hook_specific_contents,
config_file=runner.config_file,
skip_on_missing_conf=skip_on_missing_conf,
)
pre_commit_file_obj.write(contents)
Expand Down
2 changes: 1 addition & 1 deletion pre_commit/resources/commit-msg-tmpl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
args="run --hook-stage=commit-msg --commit-msg-filename=$1"
args="--hook-stage=commit-msg --commit-msg-filename=$1"
12 changes: 6 additions & 6 deletions pre_commit/resources/hook-tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ if [ -x "$HERE"/{hook_type}.legacy ]; then
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 [ $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
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 permanently silence this, install pre-commit with the `--allow-missing-config` option'
echo '- To uninstall pre-commit run `pre-commit uninstall`'
Expand All @@ -56,13 +56,13 @@ fi

# Run pre-commit
if ((WHICH_RETV == 0)); then
pre-commit $args
pre-commit run $args --config {config_file}
PRE_COMMIT_RETV=$?
elif ((ENV_PYTHON_RETV == 0)); then
"$ENV_PYTHON" -m pre_commit.main $args
"$ENV_PYTHON" -m pre_commit.main run $args
PRE_COMMIT_RETV=$?
else
python -m pre_commit.main $args
python -m pre_commit.main run $args
PRE_COMMIT_RETV=$?
fi

Expand Down
6 changes: 3 additions & 3 deletions pre_commit/resources/pre-push-tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ do
# Check that the ancestor has at least one parent
git rev-list --max-parents=0 "$local_sha" | grep "$first_ancestor" > /dev/null
if [ $? -ne 0 ]; then
args="run --all-files"
args="--all-files"
else
source=$(git rev-parse "$first_ancestor"^)
args="run --origin $local_sha --source $source"
args="--origin $local_sha --source $source"
fi
fi
else
args="run --origin $local_sha --source $remote_sha"
args="--origin $local_sha --source $remote_sha"
fi
fi
done
Expand Down
14 changes: 14 additions & 0 deletions tests/commands/install_uninstall_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_install_pre_commit(tempdir_factory):
sys_executable=sys.executable,
hook_type='pre-commit',
hook_specific='',
config_file=runner.config_file,
skip_on_missing_conf='false',
)
assert pre_commit_contents == expected_contents
Expand All @@ -72,6 +73,7 @@ def test_install_pre_commit(tempdir_factory):
sys_executable=sys.executable,
hook_type='pre-push',
hook_specific=pre_push_template_contents,
config_file=runner.config_file,
skip_on_missing_conf='false',
)
assert pre_push_contents == expected_contents
Expand Down Expand Up @@ -160,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)
Expand Down