Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Unstaged modification lost when running git hook #552

Open
ecabestan opened this issue Dec 15, 2021 · 4 comments
Open

Unstaged modification lost when running git hook #552

ecabestan opened this issue Dec 15, 2021 · 4 comments

Comments

@ecabestan
Copy link

Hi,

After running precommit hook, I have lost my unstaged modification :-(

It occurs when you have unstaged modification and ktlint detect an issue in the staged files.
The pre-commit remove modification and doesn't re-apply them as ktlint returns an error

The issue is in the pre-commit hook and seems to be fixed by Use Gradle command exit code as hook exit code.

The issue come from here : Resolve pre-commit hook causing conflicts

Do you think it is possible to create new version with this fix ? I think it can save work of many peoples :-)

I think that a better solution should be found : remove the modification in a pre-commit hook is a big risk !
The stash used before the regression has the advantage to not lost the modification. It is the first check I have done when I lost my modifications.

@JLLeitschuh
Copy link
Owner

I believe your changes may just be stashed, so you can theoretically get them back by unstashing your changes. Sorry about this. I'll see if we can get a release out this week.

@ecabestan
Copy link
Author

Sadly, the changes are not stashed. It is the first check I have done
In the previous release a stash was done in the hook. It has been replaced by a diff apply -r.

Thanks for the answer.

@JeroenErikJensen-TomTom
Copy link

JeroenErikJensen-TomTom commented Jan 12, 2022

Now with the git apply -R, your can recover your lost changes with:

git apply --ignore-whitespace .git/unstaged-ktlint-git-hook.diff

Might be useful for anybody who is affected by this issue.

Should the script not also handle the SIGINT signal (ctrl+c)?

@JonathanDeLeon
Copy link

Thanks @JeroenErikJensen-TomTom for that tip.

fyi, The latest release (10.2.1) also has a bug in it. It is fixed by Fix pre-commit hook command not found error.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants