Skip to content

Using git directly instead of a temporary file when stashing changes #1505

@Pierre-Sassoulas

Description

@Pierre-Sassoulas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions