mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Introduce .pre-commit-hooks.yaml as a replacement for hooks.yaml
This commit is contained in:
parent
b90a598fac
commit
b9e5184ebd
32 changed files with 107 additions and 21 deletions
|
|
@ -13,7 +13,7 @@ from testing.util import is_valid_according_to_schema
|
|||
@pytest.mark.parametrize(
|
||||
('input', 'expected_output'),
|
||||
(
|
||||
(['hooks.yaml'], 0),
|
||||
(['.pre-commit-hooks.yaml'], 0),
|
||||
(['non_existent_file.yaml'], 1),
|
||||
([get_resource_path('valid_yaml_but_invalid_manifest.yaml')], 1),
|
||||
([get_resource_path('non_parseable_yaml_file.notyaml')], 1),
|
||||
|
|
|
|||
|
|
@ -146,6 +146,12 @@ def log_info_mock():
|
|||
yield mck
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def log_warning_mock():
|
||||
with mock.patch.object(logging.getLogger('pre_commit'), 'warning') as mck:
|
||||
yield mck
|
||||
|
||||
|
||||
class FakeStream(object):
|
||||
def __init__(self):
|
||||
self.data = io.BytesIO()
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@ def test_cherry_pick_conflict(in_merge_conflict):
|
|||
def get_files_matching_func():
|
||||
def get_filenames():
|
||||
return (
|
||||
'.pre-commit-hooks.yaml',
|
||||
'pre_commit/main.py',
|
||||
'pre_commit/git.py',
|
||||
'im_a_file_that_doesnt_exist.py',
|
||||
'testing/test_symlink',
|
||||
'hooks.yaml',
|
||||
)
|
||||
|
||||
return git.get_files_matching(get_filenames)
|
||||
|
|
@ -81,9 +81,9 @@ def get_files_matching_func():
|
|||
def test_get_files_matching_base(get_files_matching_func):
|
||||
ret = get_files_matching_func('', '^$')
|
||||
assert ret == {
|
||||
'.pre-commit-hooks.yaml',
|
||||
'pre_commit/main.py',
|
||||
'pre_commit/git.py',
|
||||
'hooks.yaml',
|
||||
'testing/test_symlink'
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ def test_get_files_matching_total_match(get_files_matching_func):
|
|||
|
||||
def test_does_search_instead_of_match(get_files_matching_func):
|
||||
ret = get_files_matching_func('\\.yaml$', '^$')
|
||||
assert ret == {'hooks.yaml'}
|
||||
assert ret == {'.pre-commit-hooks.yaml'}
|
||||
|
||||
|
||||
def test_does_not_include_deleted_fileS(get_files_matching_func):
|
||||
|
|
@ -105,7 +105,7 @@ def test_does_not_include_deleted_fileS(get_files_matching_func):
|
|||
|
||||
def test_exclude_removes_files(get_files_matching_func):
|
||||
ret = get_files_matching_func('', '\\.py$')
|
||||
assert ret == {'hooks.yaml', 'testing/test_symlink'}
|
||||
assert ret == {'.pre-commit-hooks.yaml', 'testing/test_symlink'}
|
||||
|
||||
|
||||
def resolve_conflict():
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ def manifest(store, tempdir_factory):
|
|||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||
head_sha = get_head_sha(path)
|
||||
repo_path_getter = store.get_repo_path_getter(path, head_sha)
|
||||
yield Manifest(repo_path_getter)
|
||||
yield Manifest(repo_path_getter, path)
|
||||
|
||||
|
||||
def test_manifest_contents(manifest):
|
||||
|
|
@ -49,3 +49,21 @@ def test_hooks(manifest):
|
|||
'name': 'Bash hook',
|
||||
'stages': [],
|
||||
}
|
||||
|
||||
|
||||
def test_legacy_manifest_warn(store, tempdir_factory, log_warning_mock):
|
||||
path = make_repo(tempdir_factory, 'legacy_hooks_yaml_repo')
|
||||
head_sha = get_head_sha(path)
|
||||
repo_path_getter = store.get_repo_path_getter(path, head_sha)
|
||||
|
||||
Manifest(repo_path_getter, path).manifest_contents
|
||||
|
||||
# Should have printed a warning
|
||||
assert log_warning_mock.call_args_list[0][0][0] == (
|
||||
'{} uses legacy hooks.yaml to provide hooks.\n'
|
||||
'In newer versions, this file is called .pre-commit-hooks.yaml\n'
|
||||
'This will work in this version of pre-commit but will be removed at '
|
||||
'a later time.\n'
|
||||
'If `pre-commit autoupdate` does not silence this warning consider '
|
||||
'making an issue / pull request.'.format(path)
|
||||
)
|
||||
|
|
|
|||
9
tests/meta_test.py
Normal file
9
tests/meta_test.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import io
|
||||
|
||||
import pre_commit.constants as C
|
||||
|
||||
|
||||
def test_hooks_yaml_same_contents():
|
||||
legacy_contents = io.open(C.MANIFEST_FILE_LEGACY).read()
|
||||
contents = io.open(C.MANIFEST_FILE).read()
|
||||
assert legacy_contents == contents
|
||||
|
|
@ -45,7 +45,7 @@ def _test_hook_repo(
|
|||
args,
|
||||
expected,
|
||||
expected_return_code=0,
|
||||
config_kwargs=None
|
||||
config_kwargs=None,
|
||||
):
|
||||
path = make_repo(tempdir_factory, repo_path)
|
||||
config = make_config_from_repo(path, **(config_kwargs or {}))
|
||||
|
|
@ -215,6 +215,15 @@ def test_system_hook_with_spaces(tempdir_factory, store):
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_repo_with_legacy_hooks_yaml(tempdir_factory, store):
|
||||
_test_hook_repo(
|
||||
tempdir_factory, store, 'legacy_hooks_yaml_repo',
|
||||
'system-hook-with-spaces', ['/dev/null'], b'Hello World\n',
|
||||
config_kwargs={'legacy': True},
|
||||
)
|
||||
|
||||
|
||||
@skipif_cant_run_swift
|
||||
@pytest.mark.integration
|
||||
def test_swift_hook(tempdir_factory, store):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue