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

fix the default value for types_or #1716

Merged
merged 1 commit into from Nov 26, 2020
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
2 changes: 1 addition & 1 deletion pre_commit/clientlib.py
Expand Up @@ -61,7 +61,7 @@ def _make_argparser(filenames_help: str) -> argparse.ArgumentParser:
cfgv.Optional('files', check_string_regex, ''),
cfgv.Optional('exclude', check_string_regex, '^$'),
cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']),
cfgv.Optional('types_or', cfgv.check_array(check_type_tag), ['file']),
cfgv.Optional('types_or', cfgv.check_array(check_type_tag), []),
cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []),

cfgv.Optional(
Expand Down
6 changes: 5 additions & 1 deletion pre_commit/commands/run.py
Expand Up @@ -92,7 +92,11 @@ def by_types(
ret = []
for filename in names:
tags = self._types_for_file(filename)
if tags >= types and tags & types_or and not tags & exclude_types:
if (
tags >= types and
(not types_or or tags & types_or) and
not tags & exclude_types
):
ret.append(filename)
return ret

Expand Down
21 changes: 21 additions & 0 deletions tests/commands/run_test.py
Expand Up @@ -964,6 +964,27 @@ def test_classifier_does_not_normalize_backslashes_non_windows(tmpdir):
assert classifier.filenames == [r'a/b\c']


def test_classifier_empty_types_or(tmpdir):
tmpdir.join('bar').ensure()
tmpdir.join('foo').mksymlinkto('bar')
with tmpdir.as_cwd():
classifier = Classifier(('foo', 'bar'))
for_symlink = classifier.by_types(
classifier.filenames,
types=['symlink'],
types_or=[],
exclude_types=[],
)
for_file = classifier.by_types(
classifier.filenames,
types=['file'],
types_or=[],
exclude_types=[],
)
assert for_symlink == ['foo']
assert for_file == ['bar']


@pytest.fixture
def some_filenames():
return (
Expand Down
2 changes: 1 addition & 1 deletion tests/repository_test.py
Expand Up @@ -901,7 +901,7 @@ def test_manifest_hooks(tempdir_factory, store):
'post-commit', 'manual', 'post-checkout', 'push',
),
types=['file'],
types_or=['file'],
types_or=[],
verbose=False,
)

Expand Down