Skip to content

Commit 89ab609

Browse files
committed
fix the default value for types_or
1 parent b5baf5c commit 89ab609

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

pre_commit/clientlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _make_argparser(filenames_help: str) -> argparse.ArgumentParser:
6161
cfgv.Optional('files', check_string_regex, ''),
6262
cfgv.Optional('exclude', check_string_regex, '^$'),
6363
cfgv.Optional('types', cfgv.check_array(check_type_tag), ['file']),
64-
cfgv.Optional('types_or', cfgv.check_array(check_type_tag), ['file']),
64+
cfgv.Optional('types_or', cfgv.check_array(check_type_tag), []),
6565
cfgv.Optional('exclude_types', cfgv.check_array(check_type_tag), []),
6666

6767
cfgv.Optional(

pre_commit/commands/run.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ def by_types(
9292
ret = []
9393
for filename in names:
9494
tags = self._types_for_file(filename)
95-
if tags >= types and tags & types_or and not tags & exclude_types:
95+
if (
96+
tags >= types and
97+
(not types_or or tags & types_or) and
98+
not tags & exclude_types
99+
):
96100
ret.append(filename)
97101
return ret
98102

tests/commands/run_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,27 @@ def test_classifier_does_not_normalize_backslashes_non_windows(tmpdir):
964964
assert classifier.filenames == [r'a/b\c']
965965

966966

967+
def test_classifier_empty_types_or(tmpdir):
968+
tmpdir.join('bar').ensure()
969+
tmpdir.join('foo').mksymlinkto('bar')
970+
with tmpdir.as_cwd():
971+
classifier = Classifier(('foo', 'bar'))
972+
for_symlink = classifier.by_types(
973+
classifier.filenames,
974+
types=['symlink'],
975+
types_or=[],
976+
exclude_types=[],
977+
)
978+
for_file = classifier.by_types(
979+
classifier.filenames,
980+
types=['file'],
981+
types_or=[],
982+
exclude_types=[],
983+
)
984+
assert for_symlink == ['foo']
985+
assert for_file == ['bar']
986+
987+
967988
@pytest.fixture
968989
def some_filenames():
969990
return (

tests/repository_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def test_manifest_hooks(tempdir_factory, store):
901901
'post-commit', 'manual', 'post-checkout', 'push',
902902
),
903903
types=['file'],
904-
types_or=['file'],
904+
types_or=[],
905905
verbose=False,
906906
)
907907

0 commit comments

Comments
 (0)