New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lint-staged
doesn't restore unstaged changed when it fails
#550
lint-staged
doesn't restore unstaged changed when it fails
#550
Comments
The best way would be if you could do a PR with a failing test that does these steps. See the gitStash spec file. |
It doesn’t appear in the list of stashes because right now it’s not using git stash for that. It might change in the future, though I wouldn’t rely on it. |
Looking at the debug log I see it’s missing the restoration part completely. This isn’t how it is suppose to look like and I’m not sure what’s causing it. Please try using a different node version? |
@okonet Thank you for your response. I will look into this tomorrow. Could this be related to our specific linting setup? E.g. some unexpected exit codes. |
Definitely! What codes are you using? |
That would be the exit code of
|
That shouldn’t be a problem. Have you tried different node versions? |
Same issue with node 10.14.1 |
That’s very weird. Can you please ditch node_modules and reinstall everything and try out again? |
Ditched
This shows up while the linting is running. That seems wrong. Detailed description:
|
I'm not sure I get what you're saying. From what I see in the screen record it's not clear how it did end up in this state. Please create a repo with a reproducible case so I can try myself. |
@okonet I'll see if I am able to produce a repo with this issue, that I can share publicly. The screengrab I posted appear to be incomplete though. Here's the non-gif: https://www.dropbox.com/s/fmd1zsfnviszsko/lint-staged.mov?dl=0 Could this be related to having multiple linting steps? |
Hmm, this is definitively not how it suppose to work... I'm not sure what's causing it yet so please help me to find the root cause. I've written tests for this behavior but something with your setup still skips the restoration step. |
I had this issue as well and after various tests I found the reason! Whenever my lint-staged config sets Ok
Fails
It seems like that adding https://github.com/okonet/lint-staged/blob/master/src/runAll.js#L60 It is the same issue as #601 |
That’s great news! I think we should remove this option since it actually does more harm than good at this point. Thought? |
Please can everyone confirm if that’s the case or if the problem still remain? |
Confirmed that @Zdend's workaround works for us as well. @okonet As one of the authors, do you have any hints to why this happens? I'll be happy to open a PR to fix the issue if you have any pointers. I assume there's a reason this option was introduced at one point, so might be worthwhile looking into keeping it? Edit: Just looked through our commit history to see if I could figure out why we have concurrent: false, it appears we had git lock issues prior to adding it. Is that a known issue? |
@okonet Yes, I had this happen to me in the last 30 minutes with lint-staged 8.1.3 on Windows 10. Lost an hour of work. I will try |
We didn’t release anything related to this issue yet. |
I have just experienced this issue with |
Can you reproduce with verbose output and post it here? We should all be able to agree, that the mechanics here are so dangerous that we should add better fail safes. The git commands could fail for various reasons, unrelated to this tool. |
I just lost work as well, I'm not setting
One question is, is the work really gone? Does it store it in a tmp directory somewhere? Would it be possible to do that and print the directory until this issue is completely fixed? My work wasn't a lot, but it's scary. |
No, the work isn’t gone and there is a way to print a command to restore it but since I still don’t know how to reproduce the issue I can’t really approach it. Also, since I never experienced the issue myself (and I’m running 🚫💩 lint-staged on all my repos) I guess there is something specific what combines all those cases. But the information in this issue isn’t enough to see the pattern. That’s why I need everyone’s help. |
One input I’ve got is related to lock files and it seems to be the case but I need to understand better what’s going on |
Here's a way to reproduce it: module.exports = {
concurrent: true,
linters: {
'*.{md,html,rb}': ['touch .git/index.lock', 'git add'],
},
} Make 2 changes in a Note that you'll have to manually delete This repro is a hack to simulate what I believe is happening here. Something (maybe magit for me, or my prompt) is locking git in the midst of lint-staged doing its thing. It's a race condition and only happens sometimes. If it happens though, I get the above error and my work is "gone". (luckily it's usually in my undo buffer in emacs, but I have to remember which files were changed). Hope that helps! |
Sorry that I don't have verbose repro info, I am away from my work computer and can't set up a repro easily here. I will say that to @aaronjensen 's point it only seems to occur for me if webpack-dev-server is running in the background. |
I just lost work as well, but after reading the main source code of the project, I found that excute |
@iiroj do you think we could try repro this using your new test suit? |
@okonet sure, I can try. Still, creating a stash before running , and restoring it on success should be pretty straightforward. Let me try and reproduce this over the weekend. |
My hope is that if you’d “lock” some files for writing, you’d be able to repro it in the test. After that we could figure out a strategy for the fix. |
🎉 This issue has been resolved in version 9.5.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 10.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
this is still happening on lint-staged@12.3.7 with node@v16.13.0, just happened to me on OSX and I lost a lot of code changes on several files. my precommit hook #!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npm run lint:staged my
any ideas? |
@WagnerMoreira also struggling with code being staged and not popped properly when rubocop fails. Are you getting a PID error as well? |
Happened to me today, all changes lost after lint-staged failed |
@y3fers0n this is a pretty old issue... can you open a new one with debug logs? Did you find your changes from the |
Yes, I did found the changes there, thank you |
Description
I've experienced an issue, that I'm consistently able to reproduce.
If I do a partial staging of changes, where the staged changes contain linting errors, the unstaged changes are not restored after
lint-staged
runs.What's even more annoying is that the stashed changes doesn't appear in stash list, meaning the work is lost.
Appear to relate to #62
Steps to reproduce
Not sure how to best produce a small example that reproduces this issue. But these steps triggers the error for me:
lint-staged
Debug Logs
expand to view
Environment
lint-staged
: 8.0.4The text was updated successfully, but these errors were encountered: