-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Incorrect handling of .gitignore negate pattern #3228
Comments
It appears to be a bug with pathspec not handling exclusions correctly for directories without a trailing slash (this also gives you a workaround for this issue - just add a trailing slash): import pathspec
gitignore = """\
build
!/foo/build
"""
spec = pathspec.PathSpec.from_lines("gitwildmatch", gitignore.splitlines())
# incorrectly returns True
print(spec.match_file("foo/build/file.py"))
gitignore = """\
build
!/foo/build/
"""
spec = pathspec.PathSpec.from_lines("gitwildmatch", gitignore.splitlines())
# correctly returns False
print(spec.match_file("foo/build/file.py")) I don't think there are any open issues for this on the pathspec repo so could you report it there? |
This example was poorly chosen as build is also part of black’s default exclude regex. I will file a bug with pathspec |
Thanks, closing as the bug appears to be in our dependency, not in Black itself. |
Since it doesn't seem like you got around to it, I made an issue to track this: cpburnz/python-pathspec#57 |
Thank you @jack1142! |
Describe the bug
When adding a name to .gitignore and negating a specific directory of that name, black incorrectly ignores the files it contains.
.gitignore
To Reproduce
By running this shell script you should see that git doesn't ignore the file but black does.
The text was updated successfully, but these errors were encountered: