First, thank you for this great hook framework, I'm using it all the time.
After checking the code for removing the changes that are not stagged here, it seems that pre-commit use a temporary file that will be deleted when we leave the context of pre-commit, because it's created with a tempdir_factory.get()
with open(patch_filename, 'wb') as patch_file:
patch_file.write(diff_stdout_binary)
This means that if you halt pre-commit during its execution you can lose your unstaged changes because the temporary file disappears. I think it would be safer to stash inside git, so the changes can be recovered using git if pre-commit is halted with ctrl+C or for another problem.
This is not an hypothetical situation, by the way, we lost 3 hours of changes that way :)
Let me know if something is problematic with this approach. I could work on it.
First, thank you for this great hook framework, I'm using it all the time.
After checking the code for removing the changes that are not stagged here, it seems that pre-commit use a temporary file that will be deleted when we leave the context of pre-commit, because it's created with a
tempdir_factory.get()This means that if you halt pre-commit during its execution you can lose your unstaged changes because the temporary file disappears. I think it would be safer to stash inside git, so the changes can be recovered using git if pre-commit is halted with ctrl+C or for another problem.
This is not an hypothetical situation, by the way, we lost 3 hours of changes that way :)
Let me know if something is problematic with this approach. I could work on it.