From 4b2f83d11e69cbdf5dbd20681c59792591e55f20 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 13 Nov 2015 10:08:37 -0800 Subject: [PATCH] Fix hooks that apply non-utf8 diffs --- pre_commit/commands/run.py | 4 ++-- testing/resources/modified_file_returns_zero_repo/bin/hook.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 2004e6f3..d4929aca 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -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)) 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) - 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 diff_before != diff_after: diff --git a/testing/resources/modified_file_returns_zero_repo/bin/hook.sh b/testing/resources/modified_file_returns_zero_repo/bin/hook.sh index d4322dbd..98b05f94 100755 --- a/testing/resources/modified_file_returns_zero_repo/bin/hook.sh +++ b/testing/resources/modified_file_returns_zero_repo/bin/hook.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash for f in $@; do - echo modified > "$f" + # Non UTF-8 bytes + echo -e '\x01\x97' > "$f" echo "Modified: $f!" done