From ac0e1a60585ea903012bfadc2814874d8ab6369f Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 31 Jul 2017 08:01:28 -0700 Subject: [PATCH] Use more git plumbing commands in staged-files-only --- pre_commit/staged_files_only.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pre_commit/staged_files_only.py b/pre_commit/staged_files_only.py index 151e924a..7db17b83 100644 --- a/pre_commit/staged_files_only.py +++ b/pre_commit/staged_files_only.py @@ -20,10 +20,11 @@ def staged_files_only(cmd_runner): cmd_runner - PrefixedCommandRunner """ # Determine if there are unstaged files + tree = cmd_runner.run(('git', 'write-tree'))[1].strip() retcode, diff_stdout_binary, _ = cmd_runner.run( ( - 'git', 'diff', '--ignore-submodules', '--binary', '--exit-code', - '--no-color', '--no-ext-diff', + 'git', 'diff-index', '--ignore-submodules', '--binary', + '--exit-code', '--no-color', '--no-ext-diff', tree, '--', ), retcode=None, encoding=None, @@ -39,7 +40,7 @@ def staged_files_only(cmd_runner): patch_file.write(diff_stdout_binary) # Clear the working directory of unstaged changes - cmd_runner.run(['git', 'checkout', '--', '.']) + cmd_runner.run(('git', 'checkout', '--', '.')) try: yield finally: @@ -57,7 +58,7 @@ def staged_files_only(cmd_runner): # We failed to apply the patch, presumably due to fixes made # by hooks. # Roll back the changes made by hooks. - cmd_runner.run(['git', 'checkout', '--', '.']) + cmd_runner.run(('git', 'checkout', '--', '.')) cmd_runner.run( ('git', 'apply', patch_filename, '--whitespace=nowarn'), encoding=None,