ktlint-gradle
ktlint-gradle copied to clipboard
Unstaged modification lost when running git hook
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.
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.
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.
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)?
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.