Fix parsing of git output with unusual characters · lircs/pre-commit-hooks@4faed34 · GitHub
Skip to content

Commit 4faed34

Browse files
pawamoyasottile
authored andcommitted
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 pre-commit#508.
1 parent 5372f44 commit 4faed34

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

pre_commit_hooks/check_executables_have_shebangs.py

Lines changed: 10 additions & 2 deletions

tests/check_executables_have_shebangs_test.py

Lines changed: 25 additions & 0 deletions

0 commit comments

Comments
 (0)