summaryrefslogtreecommitdiffstats
path: root/pre_commit/staged_files_only.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-06-14 09:11:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2020-06-14 09:11:21 +0000
commitcc9f06b22c7665893e6958f7518a9e8d258e7d98 (patch)
tree19c3ef54ef886a32df2f3ed7be2f694d77b50bfc /pre_commit/staged_files_only.py
parentAdding upstream version 2.3.0. (diff)
downloadpre-commit-cc9f06b22c7665893e6958f7518a9e8d258e7d98.tar.xz
pre-commit-cc9f06b22c7665893e6958f7518a9e8d258e7d98.zip
Adding upstream version 2.5.1.upstream/2.5.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/staged_files_only.py')
-rw-r--r--pre_commit/staged_files_only.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/pre_commit/staged_files_only.py b/pre_commit/staged_files_only.py
index 09d323d..6179301 100644
--- a/pre_commit/staged_files_only.py
+++ b/pre_commit/staged_files_only.py
@@ -56,8 +56,10 @@ def _unstaged_changes_cleared(patch_dir: str) -> Generator[None, None, None]:
with open(patch_filename, 'wb') as patch_file:
patch_file.write(diff_stdout_binary)
- # Clear the working directory of unstaged changes
- cmd_output_b('git', 'checkout', '--', '.')
+ # prevent recursive post-checkout hooks (#1418)
+ no_checkout_env = dict(os.environ, _PRE_COMMIT_SKIP_POST_CHECKOUT='1')
+ cmd_output_b('git', 'checkout', '--', '.', env=no_checkout_env)
+
try:
yield
finally:
@@ -72,8 +74,9 @@ def _unstaged_changes_cleared(patch_dir: str) -> Generator[None, None, None]:
# We failed to apply the patch, presumably due to fixes made
# by hooks.
# Roll back the changes made by hooks.
- cmd_output_b('git', 'checkout', '--', '.')
+ cmd_output_b('git', 'checkout', '--', '.', env=no_checkout_env)
_git_apply(patch_filename)
+
logger.info(f'Restored changes from {patch_filename}.')
else:
# There weren't any staged files so we don't need to do anything