mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Exempt language: fail hooks from check-hooks-apply
This commit is contained in:
parent
21c2c9df33
commit
ce25b652b9
2 changed files with 31 additions and 2 deletions
|
|
@ -15,7 +15,7 @@ def check_all_hooks_match_files(config_file):
|
||||||
|
|
||||||
for repo in repositories(load_config(config_file), Store()):
|
for repo in repositories(load_config(config_file), Store()):
|
||||||
for hook_id, hook in repo.hooks:
|
for hook_id, hook in repo.hooks:
|
||||||
if hook['always_run']:
|
if hook['always_run'] or hook['language'] == 'fail':
|
||||||
continue
|
continue
|
||||||
include, exclude = hook['files'], hook['exclude']
|
include, exclude = hook['files'], hook['exclude']
|
||||||
filtered = _filter_by_include_exclude(files, include, exclude)
|
filtered = _filter_by_include_exclude(files, include, exclude)
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ def test_hook_types_excludes_everything(
|
||||||
assert 'check-useless-excludes does not apply to this repository' in out
|
assert 'check-useless-excludes does not apply to this repository' in out
|
||||||
|
|
||||||
|
|
||||||
def test_valid_includes(capsys, tempdir_factory, mock_store_dir):
|
def test_valid_always_run(capsys, tempdir_factory, mock_store_dir):
|
||||||
config = {
|
config = {
|
||||||
'repos': [
|
'repos': [
|
||||||
{
|
{
|
||||||
|
|
@ -131,3 +131,32 @@ def test_valid_includes(capsys, tempdir_factory, mock_store_dir):
|
||||||
|
|
||||||
out, _ = capsys.readouterr()
|
out, _ = capsys.readouterr()
|
||||||
assert out == ''
|
assert out == ''
|
||||||
|
|
||||||
|
|
||||||
|
def test_valid_language_fail(capsys, tempdir_factory, mock_store_dir):
|
||||||
|
config = {
|
||||||
|
'repos': [
|
||||||
|
{
|
||||||
|
'repo': 'local',
|
||||||
|
'hooks': [
|
||||||
|
# Should not be reported as an error due to language: fail
|
||||||
|
{
|
||||||
|
'id': 'changelogs-rst',
|
||||||
|
'name': 'changelogs must be rst',
|
||||||
|
'entry': 'changelog filenames must end in .rst',
|
||||||
|
'language': 'fail',
|
||||||
|
'files': r'changelog/.*(?<!\.rst)$',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
repo = git_dir(tempdir_factory)
|
||||||
|
add_config_to_repo(repo, config)
|
||||||
|
|
||||||
|
with cwd(repo):
|
||||||
|
assert check_hooks_apply.main(()) == 0
|
||||||
|
|
||||||
|
out, _ = capsys.readouterr()
|
||||||
|
assert out == ''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue