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
Improve isWorkingDirClean() check for projects with generated code #688
Conversation
Just noticed the package.json file was updated for some reason. Let me fix that.. |
f7ed557
to
255caa0
Compare
Fixed – made an error rebasing first time around. |
Thanks @jbrunton I was hoping we wouldn't need a write action (update index), even though it's only Git internals. What about the options from https://gist.github.com/sindresorhus/3898739, such as:
I'm just challenging here, if I have the time I'll try to actually set up some scenarios to test. |
@webpro: you're right to challenge, Git is a complex beast!
|
I'll take some time to read up on those other options too. I'm now wondering if |
255caa0
to
0230f6f
Compare
I did some further investigation, and I think |
@webpro oops, I forgot that gist you linked to already did the benchmarking. (I did some of my own, which probably wasn't necessary given the results in the gist, but the results appeared to be consistent.) The commands I looked at were:
As with the results in the gist, Finally, to triple check the scenarios we want to solve for:
The above commands all meet these criteria. |
lib/plugin/git/Git.js
Outdated
return this.exec('git diff-index --quiet HEAD --', { options }).then( | ||
// Note: the update-index is required here for cases where files may be touched/recreated | ||
// during a build/test hook. Git will mark those as potentially changed, but won't diff them | ||
// until the index is updated. See also https://github.com/release-it/release-it/issues/687 |
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.
I guess the comment can be removed again. Thanks for all the work! Will test this asap.
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.
whoops! removed.
For reference, I also created some scripts for testing the suitability of different commands (to sense check I was reading the docs correctly!) and for benchmarking: https://github.com/jbrunton/test-git-dirty-checks |
@webpro: just to confirm, I've addressed review comments. No hurry from my point of view, but let me know if you'd like a hand with testing (e.g. generating test cases). |
Apologies for not getting back to you earlier, and thanks for the elaborate help! Really appreciated. I'm trying to make a test case that fails with the current setup, and passes in this PR. Existing passing test: test.serial('should throw if working dir is not clean', async t => {
const gitClient = factory(Git, { options: { git } });
sh.exec('rm file');
const expected = { instanceOf: GitCleanWorkingDirError, message: /Working dir must be clean/ };
await t.throwsAsync(gitClient.init(), expected);
}); The test I had in mind on how I understand the issue: sh.exec('touch file'); or maybe sh.exec('rm file');
sh.exec('echo line > file'); However, these tests also pass with Maybe there's an issue with the result of the |
It's certainly a fun one – I've been finding the behavior quite inconsistent in some very consistent ways :) I haven't been able to figure out why, though.
For example, running inside the node terminal in the release-it repo (or any node package):
I've not been able to figure out why I see such different results depending on the environment (especially given that four of the five scenarios use node + shelljs but seem to produce different results). My own conclusion was that writing a unit test may not be feasible, but I could put together some small sample projects to demonstrate the differences through manual testing? Also: it sounds like you've been looking into scenario 4 (unit tests). Out of curiosity, have you tried any of the other cases? EDIT: no particular need for you to test all the above, but I'd be curious what you see if you use a node terminal, and I can also put together a small example for scenario 5 (running release-it in a repo). |
Small test case for scenario 5 (repo running release-it where the git checks fail): https://github.com/jbrunton/test-release-it-diff-check EDIT: I realized that the auth check may fail if you try to clone and test this repo? I can add you as a collaborator if that simplifies testing. |
Thank you for the extended research and tests, @jbrunton! I've tried a few things on the command directly and your test case repo and I'm convinced this PR is definitely an improvement. |
That's great. Thanks for merging and releasing, @webpro! |
Fix for #687
I tried to add some additional test coverage, but for some reason the behavior which I can reliably reproduce in a node terminal (see notes in #687) was only inconsistently reproducible in the tests I tried. I'm not yet clear what it is about the testing environment that causes this, but the existing tests show that the change still works for existing cases, so perhaps that's good enough?