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
refactor: use native git stashes in git workflow #633
Conversation
I believe it's missing the step 6 from #75
That's the crucial part of it that took me 2 years to realize and implement. And I'm not sure it's possible to achieve with I mentioned before I'm open to any suggestion that would keep tests green. Please update tests in order to see if some are broken and we can discuss further from there. How does that sound? |
Do you mean that in the case of linter failures during formatting changes, the changes should be left in the working copy? This branch will always revert any changes during error, and return to the identical status before committing. Maybe I'm misunderstading the current behaviour, but I did see I was only running the stash/pop with partial files (should run always). |
Not quite: the step 6 is for the case when there are no errors during formatting but the contents did change. Since there is a new content in files that were stashed See https://github.com/okonet/lint-staged/pull/633/files#diff-cf453db1a0c4f207753345e32ef28aa3L121 for the explanation on how it works. |
I think easiest way is to do the refactoring without changing function names that are being used in the |
Maybe this branch then completely circumvents that issue, since in this case the stash is only applied before running linters (but not removed, since we use If there are no errors, the process will just remove the stash but not try to do anything else. This might actually change behaviour in the sense that running EDIT: |
I ”fixed” most of the tests. There’s a lot of tests that mostly test the old stash/pop functions, but this method doesn’t really rely on those so they are not needed. Overall things seem to work around the same considering the start and end results. Maybe this needs some new tests, but first we should validate the logic is the same before investing into those. What do you think? |
This will make lint-staged always remove any changes during linting, if there are errors
Codecov Report
@@ Coverage Diff @@
## master #633 +/- ##
=========================================
+ Coverage 98.14% 98.75% +0.6%
=========================================
Files 14 14
Lines 378 321 -57
Branches 51 44 -7
=========================================
- Hits 371 317 -54
+ Misses 7 4 -3
Continue to review full report at Codecov.
|
Alright, so the tests should now be green. I renamed the tasks in
I figure there are 8 different scenarios/combinations of behaviour that should be tested:
Maybe if I rewrite the |
I've added all these 8 test cases in a new test at I think this nicely demonstrates that the refactor handles failure cases nicely, and even preserves old edits and staged/unstaged differences. What are your thoughts, @okonet? |
I see now in case 6, that even though I have staged a partial file, since the command is Is this the same behaviour as currently? |
No, and that’s exactly the trick here. We only want to add modifications for staged hunks and not everything. I think my tests had all those scenarios handled, aren’t they? Also, when you mean I’m reading the code now so I can give you more feedback. |
I checkout our the code and the change surface is just too big to grasp for me know. Would you consider going back to my test suite for now and leave copy changes out until we have a working solution, please? That would help me better understand your changes. Pretty please? Edit: I was able to comprehend your changes but some tests were "fixed" improperly. I left a comment. |
@@ -501,8 +465,10 @@ MM test.js" | |||
|
|||
|
|||
|
|||
foo: "baz" | |||
};`) | |||
foo: ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's incorrect since this should be now "fixed"
I'll revisit this with the logic of only linting stashes, but might be that this method does not work after all. 😅 In that case I'll close this PR. |
This PR overhauls and simplifies the behaviour of the git workflow to work like this:
When run, lint-staged will:
git stash save "temporary lint-staged stash"
.git stash apply --index
. This will "remember" staged files from other modifications. We are now back to square one, but we have still have the stash.git reset --hard
to clear everything.This seems very simple and performs fast. If I understood the workflow correctly, this is the wanted behaviour. Besides, if anything fails before the final step, the stash will be left for the user to revert.
I didn't touch the tests yet, because I wanted to open this PR for discussion. I did try this out on our large monorepo, where it performs correctly as in the git state remains unchanged after commits, and in the case partial commits fail.
Thoughts?