mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Minor fixups
This commit is contained in:
parent
478b0c70d8
commit
dbd131f646
4 changed files with 22 additions and 18 deletions
|
|
@ -39,7 +39,7 @@ def is_previous_pre_commit(filename):
|
||||||
|
|
||||||
def install(
|
def install(
|
||||||
runner, overwrite=False, hooks=False, hook_type='pre-commit',
|
runner, overwrite=False, hooks=False, hook_type='pre-commit',
|
||||||
skip_on_missing_conf=False
|
skip_on_missing_conf=False,
|
||||||
):
|
):
|
||||||
"""Install the pre-commit hooks."""
|
"""Install the pre-commit hooks."""
|
||||||
hook_path = runner.get_hook_path(hook_type)
|
hook_path = runner.get_hook_path(hook_type)
|
||||||
|
|
@ -78,7 +78,7 @@ def install(
|
||||||
sys_executable=sys.executable,
|
sys_executable=sys.executable,
|
||||||
hook_type=hook_type,
|
hook_type=hook_type,
|
||||||
pre_push=pre_push_contents,
|
pre_push=pre_push_contents,
|
||||||
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)
|
||||||
make_executable(hook_path)
|
make_executable(hook_path)
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ def main(argv=None):
|
||||||
return install(
|
return install(
|
||||||
runner, overwrite=args.overwrite, hooks=args.install_hooks,
|
runner, overwrite=args.overwrite, hooks=args.install_hooks,
|
||||||
hook_type=args.hook_type,
|
hook_type=args.hook_type,
|
||||||
skip_on_missing_conf=args.allow_missing_config
|
skip_on_missing_conf=args.allow_missing_config,
|
||||||
)
|
)
|
||||||
elif args.command == 'install-hooks':
|
elif args.command == 'install-hooks':
|
||||||
return install_hooks(runner)
|
return install_hooks(runner)
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,13 @@ fi
|
||||||
CONF_FILE=$(git rev-parse --show-toplevel)"/.pre-commit-config.yaml"
|
CONF_FILE=$(git rev-parse --show-toplevel)"/.pre-commit-config.yaml"
|
||||||
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 '`.pre-commit-config.yaml` config file not found. Skipping `pre-commit`.'
|
||||||
exit $retv
|
exit $retv
|
||||||
else
|
else
|
||||||
echo 'No .pre-commit-config.yaml file was found\n'\
|
echo 'No .pre-commit-config.yaml file was found'
|
||||||
'- To temporarily silence this, run `PRE_COMMIT_ALLOW_NO_CONFIG=1 git ...`\n'\
|
echo '- To temporarily silence this, run `PRE_COMMIT_ALLOW_NO_CONFIG=1 git ...`'
|
||||||
'- To permanently silence this, install pre-commit with the `--allow-missing-config` option\n'\
|
echo '- To permanently silence this, install pre-commit with the `--allow-missing-config` option'
|
||||||
'- To uninstall pre-commit run `pre-commit uninstall`'
|
echo '- To uninstall pre-commit run `pre-commit uninstall`'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ def test_install_pre_commit(tempdir_factory):
|
||||||
sys_executable=sys.executable,
|
sys_executable=sys.executable,
|
||||||
hook_type='pre-commit',
|
hook_type='pre-commit',
|
||||||
pre_push='',
|
pre_push='',
|
||||||
skip_on_missing_conf='false'
|
skip_on_missing_conf='false',
|
||||||
)
|
)
|
||||||
assert pre_commit_contents == expected_contents
|
assert pre_commit_contents == expected_contents
|
||||||
assert os.access(runner.pre_commit_path, os.X_OK)
|
assert os.access(runner.pre_commit_path, os.X_OK)
|
||||||
|
|
@ -81,7 +81,7 @@ def test_install_pre_commit(tempdir_factory):
|
||||||
sys_executable=sys.executable,
|
sys_executable=sys.executable,
|
||||||
hook_type='pre-push',
|
hook_type='pre-push',
|
||||||
pre_push=pre_push_template_contents,
|
pre_push=pre_push_template_contents,
|
||||||
skip_on_missing_conf='false'
|
skip_on_missing_conf='false',
|
||||||
)
|
)
|
||||||
assert pre_push_contents == expected_contents
|
assert pre_push_contents == expected_contents
|
||||||
|
|
||||||
|
|
@ -579,8 +579,11 @@ def test_install_allow_mising_config(tempdir_factory):
|
||||||
|
|
||||||
ret, output = _get_commit_output(tempdir_factory)
|
ret, output = _get_commit_output(tempdir_factory)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert '`.pre-commit-config.yaml` config file not found. '\
|
expected = (
|
||||||
'Skipping `pre-commit`.' in output
|
'`.pre-commit-config.yaml` config file not found. '
|
||||||
|
'Skipping `pre-commit`.'
|
||||||
|
)
|
||||||
|
assert expected in output
|
||||||
|
|
||||||
|
|
||||||
def test_install_temporarily_allow_mising_config(tempdir_factory):
|
def test_install_temporarily_allow_mising_config(tempdir_factory):
|
||||||
|
|
@ -591,10 +594,11 @@ def test_install_temporarily_allow_mising_config(tempdir_factory):
|
||||||
remove_config_from_repo(path)
|
remove_config_from_repo(path)
|
||||||
assert install(runner, overwrite=True, skip_on_missing_conf=False) == 0
|
assert install(runner, overwrite=True, skip_on_missing_conf=False) == 0
|
||||||
|
|
||||||
extra_env = {'PRE_COMMIT_ALLOW_NO_CONFIG': '1'}
|
env = dict(os.environ, PRE_COMMIT_ALLOW_NO_CONFIG='1')
|
||||||
env = os.environ.copy()
|
|
||||||
env.update(extra_env)
|
|
||||||
ret, output = _get_commit_output(tempdir_factory, env=env)
|
ret, output = _get_commit_output(tempdir_factory, env=env)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert '`.pre-commit-config.yaml` config file not found. '\
|
expected = (
|
||||||
'Skipping `pre-commit`.' in output
|
'`.pre-commit-config.yaml` config file not found. '
|
||||||
|
'Skipping `pre-commit`.'
|
||||||
|
)
|
||||||
|
assert expected in output
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue