Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

! doesn't exclude files in directories if the pattern doesn't have a trailing slash #57

Closed
Jackenmen opened this issue Aug 22, 2022 · 1 comment

Comments

@Jackenmen
Copy link

It appears that pathspec is not handling exclusions correctly for directories without 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"))

If you try doing the same with .gitignore, it works correctly:

git init repro
cd repro
echo $'build\n!/foo/build' > .gitignore
mkdir build
touch build/file.py
mkdir -p foo/build
touch foo/build/file.py

Running git status gives:

On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitignore
	foo/

nothing added to commit but untracked files present (use "git add" to track)

And running git ls-files --others --exclude-standard gives:

.gitignore
foo/build/file.py
@cpburnz
Copy link
Owner

cpburnz commented Aug 24, 2022

This is now fixed and will be in the v0.10.0 release.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants