Skip to content

Commit ce25b65

Browse files
committed
Exempt language: fail hooks from check-hooks-apply
1 parent 21c2c9d commit ce25b65

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

pre_commit/meta_hooks/check_hooks_apply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def check_all_hooks_match_files(config_file):
1515

1616
for repo in repositories(load_config(config_file), Store()):
1717
for hook_id, hook in repo.hooks:
18-
if hook['always_run']:
18+
if hook['always_run'] or hook['language'] == 'fail':
1919
continue
2020
include, exclude = hook['files'], hook['exclude']
2121
filtered = _filter_by_include_exclude(files, include, exclude)

tests/meta_hooks/check_hooks_apply_test.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_hook_types_excludes_everything(
106106
assert 'check-useless-excludes does not apply to this repository' in out
107107

108108

109-
def test_valid_includes(capsys, tempdir_factory, mock_store_dir):
109+
def test_valid_always_run(capsys, tempdir_factory, mock_store_dir):
110110
config = {
111111
'repos': [
112112
{
@@ -131,3 +131,32 @@ def test_valid_includes(capsys, tempdir_factory, mock_store_dir):
131131

132132
out, _ = capsys.readouterr()
133133
assert out == ''
134+
135+
136+
def test_valid_language_fail(capsys, tempdir_factory, mock_store_dir):
137+
config = {
138+
'repos': [
139+
{
140+
'repo': 'local',
141+
'hooks': [
142+
# Should not be reported as an error due to language: fail
143+
{
144+
'id': 'changelogs-rst',
145+
'name': 'changelogs must be rst',
146+
'entry': 'changelog filenames must end in .rst',
147+
'language': 'fail',
148+
'files': r'changelog/.*(?<!\.rst)$',
149+
},
150+
],
151+
},
152+
],
153+
}
154+
155+
repo = git_dir(tempdir_factory)
156+
add_config_to_repo(repo, config)
157+
158+
with cwd(repo):
159+
assert check_hooks_apply.main(()) == 0
160+
161+
out, _ = capsys.readouterr()
162+
assert out == ''

0 commit comments

Comments
 (0)