Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more git plumbing commands in staged-files-only #571

Merged
merged 1 commit into from
Aug 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions pre_commit/staged_files_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand All @@ -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,
Expand Down