Whole file

pre-commit/pre-commit-hooks

The author described this change as Fix #518, provide --enforce-all option to check_added_large_files. It counts as a record because the check below fails on the code as it stood at 31d41ff29 and passes on 012bb0691, with nothing else changed between the two runs.

Fix saved2020-09-27
Sharing licenceMIT · LICENSE
Change size+21 4

What the code was meant to do, written into the code itself as a save note

Fix #518, provide --enforce-all option to check_added_large_files

The change

2121 return set(json.loads(lfs_ret)['files'])
2222
2323
24-def find_large_added_files(filenames: Sequence[str], maxkb: int) -> int:
24+def find_large_added_files(
25+ filenames: Sequence[str],
26+ maxkb: int,
27+ *,
28+ enforce_all: bool = False,
29+) -> int:
2530 # Find all added files that are also in the list of files pre-commit tells
2631 # us about
2732 retv = 0
28- for filename in (added_files() & set(filenames)) - lfs_files():
33+ filenames_filtered = set(filenames) - lfs_files()
34+ if not enforce_all:
35+ filenames_filtered &= added_files()
36+
37+ for filename in filenames_filtered:
2938 kb = int(math.ceil(os.stat(filename).st_size / 1024))
3039 if kb > maxkb:
3140 print(f'{filename} ({kb} KB) exceeds {maxkb} KB.')
4150 help='Filenames pre-commit believes are changed.',
4251 )
4352 parser.add_argument(
53+ '--enforce-all', action='store_true',
54+ help='Enforce all files are checked, not just staged files.',
55+ )
56+ parser.add_argument(
4457 '--maxkb', type=int, default=500,
4558 help='Maxmimum allowable KB for added files',
4659 )
47-
4860 args = parser.parse_args(argv)
49- return find_large_added_files(args.filenames, args.maxkb)
61+
62+ return find_large_added_files(
63+ args.filenames,
64+ args.maxkb,
65+ enforce_all=args.enforce_all,
66+ )
5067
5168
5269 if __name__ == '__main__':

The check that tells the two apart

failpass·tests/check_added_large_files_test.py::test_enforce_all

Check file tests/check_added_large_files_test.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it31d41ff29115a87808277ee0ec23999b17d5b583
Broken version dated2020-08-26
Modulepre_commit_hooks.check_added_large_files
Units changedfind_large_added_files, main
Fingerprint2fb76db6a328deeb
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in pre-commit/pre-commit-hooks