Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make repo: meta only apply to top level configuration #2026

Merged
merged 1 commit into from Aug 28, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pre_commit/clientlib.py
Expand Up @@ -216,14 +216,14 @@ def warn_unknown_keys_repo(
(
'check-hooks-apply', (
('name', 'Check hooks apply to the repository'),
('files', C.CONFIG_FILE),
('files', f'^{re.escape(C.CONFIG_FILE)}$'),
('entry', _entry('check_hooks_apply')),
),
),
(
'check-useless-excludes', (
('name', 'Check for useless excludes'),
('files', C.CONFIG_FILE),
('files', f'^{re.escape(C.CONFIG_FILE)}$'),
('entry', _entry('check_useless_excludes')),
),
),
Expand Down
11 changes: 11 additions & 0 deletions tests/clientlib_test.py
@@ -1,4 +1,5 @@
import logging
import re

import cfgv
import pytest
Expand All @@ -10,6 +11,7 @@
from pre_commit.clientlib import CONFIG_SCHEMA
from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION
from pre_commit.clientlib import MANIFEST_SCHEMA
from pre_commit.clientlib import META_HOOK_DICT
from pre_commit.clientlib import MigrateShaToRev
from pre_commit.clientlib import validate_config_main
from pre_commit.clientlib import validate_manifest_main
Expand Down Expand Up @@ -392,6 +394,15 @@ def test_meta_hook_invalid(config_repo):
cfgv.validate(config_repo, CONFIG_REPO_DICT)


def test_meta_check_hooks_apply_only_at_top_level():
cfg = {'id': 'check-hooks-apply'}
cfg = cfgv.apply_defaults(cfg, META_HOOK_DICT)

files_re = re.compile(cfg['files'])
assert files_re.search('.pre-commit-config.yaml')
assert not files_re.search('foo/.pre-commit-config.yaml')


@pytest.mark.parametrize(
'mapping',
(
Expand Down