diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-06-14 09:11:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-06-14 09:11:24 +0000 |
commit | 1312af87e5908ac252c0659a60216e96ec5b23bd (patch) | |
tree | 7621ad7267ffb9ecd8339983fd83150abc99082f /pre_commit/staged_files_only.py | |
parent | Releasing debian version 2.3.0-1. (diff) | |
download | pre-commit-1312af87e5908ac252c0659a60216e96ec5b23bd.tar.xz pre-commit-1312af87e5908ac252c0659a60216e96ec5b23bd.zip |
Merging upstream version 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.py | 9 |
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 |