pre-commit-hooks/pre_commit_hooks
Timothée Mazzucotelli 4faed34fbc Fix parsing of git output with unusual characters
On Windows, all files are "executable".
Therefore, to know if a file is supposed to be executed,
we check how its attributes were recorded by git:
we run a `git ls-files` command in a subprocess.

By default, this command outputs information
on multiple lines (file and their data separated by newlines).
When a file contains an unusual character,
the character is escaped with an integer sequence
(such as `\303\261`), and git wraps the whole filename
in double-quotes because of the backslashes.
It breaks the current code because we try to open
the filename containing the double-quotes:
it doesn't exist, of course.

Instead of trying to fix this special case by removing
the double-quotes, and breaking other cases
(a double-quote is a valid filename character on Linux),
we tell git to separate each item with the null character `\0`
instead of a new line `\n`, with the option `-z`.
With this option, git doesn't escape unusual characters
with integer sequence, so the output is fixed, and we
parse it by splitting on `\0` instead of `\n`.

Fixes #508.
2020-07-30 11:58:24 -07:00
..
__init__.py Initial commit. 2014-03-13 08:41:35 -07:00
check_added_large_files.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_ast.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_builtin_literals.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_byte_order_marker.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_case_conflict.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_docstring_first.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_executables_have_shebangs.py Fix parsing of git output with unusual characters 2020-07-30 11:58:24 -07:00
check_json.py check-json: resolve TODO 2020-05-14 16:29:55 -07:00
check_merge_conflict.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_symlinks.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_toml.py Support checking unicode TOML 2020-05-16 21:05:37 -04:00
check_vcs_permalinks.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
check_xml.py Remove type: ignore 2020-05-16 22:21:03 -04:00
check_yaml.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
debug_statement_hook.py Add "pydevd_pycharm" to list of debug statements 2020-07-01 17:15:46 +02:00
detect_aws_credentials.py Allow arbitrarily encoded files to be checked with detect-aws-credentials 2020-02-18 10:24:17 -08:00
detect_private_key.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
end_of_file_fixer.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
file_contents_sorter.py sed -i s/whitelist/allowlist/g 2020-06-17 08:27:11 -07:00
fix_encoding_pragma.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
forbid_new_submodules.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
mixed_line_ending.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
no_commit_to_branch.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
pretty_format_json.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
removed.py hotfix: the user may be define an extra arguments for a removed hook 2020-05-18 19:57:49 -07:00
requirements_txt_fixer.py Parse more operators in requirements 2020-05-18 17:25:48 -04:00
sort_simple_yaml.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
string_fixer.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
tests_should_end_in_test.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
trailing_whitespace_fixer.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00
util.py pre-commit-hooks: python3.6+ 2020-02-05 11:22:18 -08:00