Use walker from ignore crate - #2756
Conversation
| builder.standard_filters(false); | ||
| } else { | ||
| builder.require_git(false); | ||
| builder.add_custom_ignore_filename(".gitignore"); |
There was a problem hiding this comment.
Is this really necessary? Wouldn't this be one of the standard filters?
There was a problem hiding this comment.
true, just removed this and behavior stayed as expected with all tests passing
There was a problem hiding this comment.
🤔 but it's still here? Or is GitHub showing this on a line of code that is not the original of this comment?
There was a problem hiding this comment.
current code is rust if unrestricted { builder.standard_filters(false); } else { builder.add_custom_ignore_filename(".gitignore"); }
we cant remove any of those lines if we want the tests to pass
There was a problem hiding this comment.
Hrm... I'm reading the library docs and it seems to me that the behavior would be the same without this else. Am I missing something?
| // Disables .gitignore parsing, global ignores, and .git/ exclusion natively. | ||
| builder.standard_filters(false); | ||
| } else { | ||
| builder.require_git(false); |
There was a problem hiding this comment.
I find this actually interesting. I think we should have a test for current behavior in default branch prior to this PR.
There was a problem hiding this comment.
i just checked this against the code present in master
- in unrestricted: the walker does traverse
.git. this seems expected to me. any user could probably just add.gitto their ignore list manually - in "normal" mode,
.gitis not traversed
i can confirm this behavior is what we have in the new branch, and added 2 new tests to check both cases
There was a problem hiding this comment.
What about this part from the require_git docs
In particular, if this is
falsethen.gitignorefiles will be read from parent directories above the git root directory containing.git, which is different from the git behavior.
Do you think we have a test for this in master?
|
Would it be more prudent that tests that pass in the default branch be added in a prior PR? |
|
I can add them in another PR if that's something you'd prefer |
|
Well, I think achieving the coverage that will give us (me as reviewer?) confidence with regards to suggested changes, as an independent step, with no implementation changes, on the default branch, would mean I don't have to take your word on it, nor do I have to test it myself. |
|
fair enough! do you want me to add all the tests in a separate PR first (even the non-passing one with the nested gitignores) or only the ones that pass (hidden files, missing path, and the tests regarding |
|
Thank you for asking. I'd be most convenienced with a precursor PR that has all the passing tests. |
|
Oh, and that precursor PR would have no implementation changes. |
|
Thanks for your reply, i just created the new PR |
|
Brilliant, thank you! Would you mind rebasing? |
|
that would be it. please tell me if anything else needs fixing. otherwise, i believe that you can squash merge that |
mightyiam
left a comment
There was a problem hiding this comment.
🤔 are we missing precursor test in the default branch for current behavior that has to do with the behavior that is described in WalkBuilder::require_git?
| builder.standard_filters(false); | ||
| } else { | ||
| builder.require_git(false); | ||
| builder.add_custom_ignore_filename(".gitignore"); |
There was a problem hiding this comment.
🤔 but it's still here? Or is GitHub showing this on a line of code that is not the original of this comment?
|
|
||
| Ok(builder | ||
| .build() | ||
| .filter_map(Result::ok) |
There was a problem hiding this comment.
Are we currently ignoring walk errors?
There was a problem hiding this comment.
what do you mean buy walk errors? as talked in the previous PR and added in the new test, it exist with 0 (no error) on the missing_path error. this is current behavior and stays the case after this PR.
There was a problem hiding this comment.
This filter_map seems to ignore walking errors.
There was a problem hiding this comment.
For example, if the directory is removed during the walk 🤷, we'd probably get an error here and this would ignore that error. I don't think we should be ignoring such errors.
There was a problem hiding this comment.
But regardless of what we should be doing, it is more important that we don't change existing behavior. Perhaps a test that triggers a walk error. I think such a test can be achieved by removing the read permission bit of a file inside the target directory. It should be a precursor, existing behavior test, if I get to decide.
There was a problem hiding this comment.
i believe it would be a good idea (in a later PR probably?) to change the some error behaviors, especially the fact that, on a missing path, the programs exits with status code 0 (no error).
i don't really know how we could test the removal of a directory during traversal or equivalent though.
adding more tests around error behaviors later could be a good idea though
| builder.standard_filters(false); | ||
| } else { | ||
| builder.require_git(false); | ||
| builder.add_custom_ignore_filename(".gitignore"); |
There was a problem hiding this comment.
Hrm... I'm reading the library docs and it seems to me that the behavior would be the same without this else. Am I missing something?
| }); | ||
|
|
||
| Ok(builder.build().filter_map(|entry| { | ||
| let entry = entry.ok()?; |
There was a problem hiding this comment.
To continue conversation about error handling of walk errors: this seems to just ignore these errors. As I wrote elsewhere, would you be happy adding a test in a precursor PR that confirms whateber the current behavior is?
There was a problem hiding this comment.
Continuing from #2756 (comment)
i believe it would be a good idea (in a later PR probably?) to change the some error behaviors, especially the fact that, on a missing path, the programs exits with status code 0 (no error).
I don't have the confidence that that is the current behavior. That is why I am interested in having a test added in a precursor PR to confirm whatever the current bevahior is.
i don't really know how we could test the removal of a directory during traversal or equivalent though. adding more tests around error behaviors later could be a good idea though
I think this could be achieved by having a file with the read permission bit removed, within the target directory.
|
@mightyiam Continuing the conversation here because for some reason GitHub doesnt let me reply in the thread about the |
|
Just rebased the branch to includes tests from #2759 |
mightyiam
left a comment
There was a problem hiding this comment.
Sorry for not finding all my concerns in one go 😅
| // Disables .gitignore parsing, global ignores, and .git/ exclusion natively. | ||
| builder.standard_filters(false); | ||
| } else { | ||
| builder.require_git(false); |
There was a problem hiding this comment.
What about this part from the require_git docs
In particular, if this is
falsethen.gitignorefiles will be read from parent directories above the git root directory containing.git, which is different from the git behavior.
Do you think we have a test for this in master?
| for i in ignore { | ||
| gitignore.add_line(None, i.as_str())?; | ||
| for ignore_rule in extra_ignores { | ||
| gitignore.add_line(None, ignore_rule)?; |
There was a problem hiding this comment.
🤔 I'm also concerned about not having a test with regards to --ignore not ignoring files it should not. And its behavior with regards to files inside directories. And its behavior with arguments that are paths, not only filenames.
As discussed in #2751, this PR rewrites the
walk_nix_filesfunction to useWalkBuilderfrom theignorecrate directly.This also adds support for nested gitignores and a new test for those.