mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #290 from pre-commit/fix_non_utf8_diffs
Fix hooks that apply non-utf8 diffs
This commit is contained in:
commit
a0636f1fab
2 changed files with 4 additions and 3 deletions
|
|
@ -85,9 +85,9 @@ def _run_single_hook(hook, repo, args, write, skips=frozenset()):
|
||||||
write(get_hook_message(_hook_msg_start(hook, args.verbose), end_len=6))
|
write(get_hook_message(_hook_msg_start(hook, args.verbose), end_len=6))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
diff_before = cmd_output('git', 'diff', retcode=None)
|
diff_before = cmd_output('git', 'diff', retcode=None, encoding=None)
|
||||||
retcode, stdout, stderr = repo.run_hook(hook, filenames)
|
retcode, stdout, stderr = repo.run_hook(hook, filenames)
|
||||||
diff_after = cmd_output('git', 'diff', retcode=None)
|
diff_after = cmd_output('git', 'diff', retcode=None, encoding=None)
|
||||||
|
|
||||||
# If the hook makes changes, fail the commit
|
# If the hook makes changes, fail the commit
|
||||||
if diff_before != diff_after:
|
if diff_before != diff_after:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
for f in $@; do
|
for f in $@; do
|
||||||
echo modified > "$f"
|
# Non UTF-8 bytes
|
||||||
|
echo -e '\x01\x97' > "$f"
|
||||||
echo "Modified: $f!"
|
echo "Modified: $f!"
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue