mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Use more git plumbing commands in staged-files-only
This commit is contained in:
parent
972106c2d7
commit
ac0e1a6058
1 changed files with 5 additions and 4 deletions
|
|
@ -20,10 +20,11 @@ def staged_files_only(cmd_runner):
|
||||||
cmd_runner - PrefixedCommandRunner
|
cmd_runner - PrefixedCommandRunner
|
||||||
"""
|
"""
|
||||||
# Determine if there are unstaged files
|
# Determine if there are unstaged files
|
||||||
|
tree = cmd_runner.run(('git', 'write-tree'))[1].strip()
|
||||||
retcode, diff_stdout_binary, _ = cmd_runner.run(
|
retcode, diff_stdout_binary, _ = cmd_runner.run(
|
||||||
(
|
(
|
||||||
'git', 'diff', '--ignore-submodules', '--binary', '--exit-code',
|
'git', 'diff-index', '--ignore-submodules', '--binary',
|
||||||
'--no-color', '--no-ext-diff',
|
'--exit-code', '--no-color', '--no-ext-diff', tree, '--',
|
||||||
),
|
),
|
||||||
retcode=None,
|
retcode=None,
|
||||||
encoding=None,
|
encoding=None,
|
||||||
|
|
@ -39,7 +40,7 @@ def staged_files_only(cmd_runner):
|
||||||
patch_file.write(diff_stdout_binary)
|
patch_file.write(diff_stdout_binary)
|
||||||
|
|
||||||
# Clear the working directory of unstaged changes
|
# Clear the working directory of unstaged changes
|
||||||
cmd_runner.run(['git', 'checkout', '--', '.'])
|
cmd_runner.run(('git', 'checkout', '--', '.'))
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -57,7 +58,7 @@ def staged_files_only(cmd_runner):
|
||||||
# We failed to apply the patch, presumably due to fixes made
|
# We failed to apply the patch, presumably due to fixes made
|
||||||
# by hooks.
|
# by hooks.
|
||||||
# Roll back the changes made by hooks.
|
# Roll back the changes made by hooks.
|
||||||
cmd_runner.run(['git', 'checkout', '--', '.'])
|
cmd_runner.run(('git', 'checkout', '--', '.'))
|
||||||
cmd_runner.run(
|
cmd_runner.run(
|
||||||
('git', 'apply', patch_filename, '--whitespace=nowarn'),
|
('git', 'apply', patch_filename, '--whitespace=nowarn'),
|
||||||
encoding=None,
|
encoding=None,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue