@@ -56,8 +56,10 @@ def _unstaged_changes_cleared(patch_dir: str) -> Generator[None, None, None]:
5656 with open (patch_filename , 'wb' ) as patch_file :
5757 patch_file .write (diff_stdout_binary )
5858
59- # Clear the working directory of unstaged changes
60- cmd_output_b ('git' , 'checkout' , '--' , '.' )
59+ # prevent recursive post-checkout hooks (#1418)
60+ no_checkout_env = dict (os .environ , _PRE_COMMIT_SKIP_POST_CHECKOUT = '1' )
61+ cmd_output_b ('git' , 'checkout' , '--' , '.' , env = no_checkout_env )
62+
6163 try :
6264 yield
6365 finally :
@@ -72,8 +74,9 @@ def _unstaged_changes_cleared(patch_dir: str) -> Generator[None, None, None]:
7274 # We failed to apply the patch, presumably due to fixes made
7375 # by hooks.
7476 # Roll back the changes made by hooks.
75- cmd_output_b ('git' , 'checkout' , '--' , '.' )
77+ cmd_output_b ('git' , 'checkout' , '--' , '.' , env = no_checkout_env )
7678 _git_apply (patch_filename )
79+
7780 logger .info (f'Restored changes from { patch_filename } .' )
7881 else :
7982 # There weren't any staged files so we don't need to do anything
0 commit comments