-
Notifications
You must be signed in to change notification settings - Fork 39
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
Incorrectly (?) matches files inside directories that do match #41
Comments
Hi @adrienverge, Due to the current implementation it makes sense to me why p = pathspec.PathSpec.from_lines('gitwildmatch', [
'*.yaml',
'!*.yaml/'
])
p.match_file('file.yaml')
# True
p.match_file('dir.yaml/file.sql')
# False Please let me know whether this works for you. I realize this may or may not work depending on your use case. |
Thanks for your answer @cpburnz! To complete it, I notice that Git + The However, while it works with Git and
Said differently: p = pathspec.PathSpec.from_lines('gitwildmatch', ['*.yaml', '!*.yaml/'])
p.match_file('dir/file.yaml') # True
p.match_file('dir.yaml/file.yaml') # False ← I would expect True (like with .gitignore) |
Partially reverts a221898 to fix #334 Linked to cpburnz/python-pathspec#41.
@adrienverge Oops, I overlooked that. This can still be accomplished be adding an addition pattern to reinclude p = pathspec.PathSpec.from_lines('gitwildmatch', ['*.yaml', '!*.yaml/', '*.yaml/**/*.yaml'])
p.match_file('dir/file.yaml') # True
p.match_file('dir.yaml/index.txt') # False
p.match_file('dir.yaml/file.yaml') # True The |
Thanks again @cpburnz! Unfortunately this recursive pattern including/excluding seems to bring new problems:
So I understand that pathspec implements the standard, while Git adds some user-friendly, non-standard processing. (PS: I don't know how others use your useful library pathspec, but my guess is that 99% are looking for something that behaves exactly like |
@adrienverge That is indeed problematic without a good solution for current feature set.
Precisely
It's certainly doable. I think the ideal implementation would be a class implementing the
The answer isn't no, but I am aware of another library that tries to specifically implement
That seems to be the case. My original use case was I wanted a library with glob-like file matching similar to git or rsync. |
Thanks again for following this up @cpburnz 👍 @liopic @dafyddj @jsok you are the ones affected by this (via adrienverge/yamllint#279 and adrienverge/yamllint#334), would you like to contribute to python-pathspec and implement a If not, I can try to find time myself but I don't know precisely when it could be. I already went forward and found this relevant code for |
@adrienverge Interesting to read, but I am not a developer so I don't think I can help with this - but good luck! |
Guys this is not a bug. Git works exactly as the spec says:
|
@excitoon I think it's an edge case not adequately described in the gitignore specification. Git behaves exactly as described in this issue, and at the moment pathspec behaves differently. I'm working fixing the discrepancy. |
@cpburnz You can check how I solved it in my module. First, making a group for extra path parts: Second, analyzing if anything matched. If it did not, we shall query filesystem to check if it is a directory: |
One more example:
|
There will be a way to handle this scenario in the v0.10.0 release. The new class, # The "gitwildmatch" pattern factory is assumed by GitIgnoreSpec.
p = pathspec.GitIgnoreSpec.from_lines(['*.yaml', '!*.yaml/'])
p.match_file('dir/file.yaml') # True
p.match_file('dir.yaml/file.yaml') # True |
Thanks @cpburnz! |
Hello @cpburnz, I've looked existing issues but couldn't find this one. It was initially reported in yamllint issues: adrienverge/yamllint#334 (yamllint uses pathspec).
Considering these files:
pathspec.PathSpec.from_lines('gitwildmatch', ['*.yaml'])
does matchfile.yaml
,dir.yaml
, but alsodir.yaml/file.sql
. The latter isn't what I would expect, because*.yaml
feels like "files that end with .yaml", not "any file in any path that contains .yaml".Is it the expected behavior? If yes, what is the correct pattern for "files that end with .yaml"?
Looking forward to your answer, and thanks for this very useful project 👍
The text was updated successfully, but these errors were encountered: