Match directory entries with directory-only patterns - #147
Merged
Merged
Conversation
Owner
|
Thanks for finding and fixing this! |
cpburnz
added a commit
that referenced
this pull request
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
match_entries()passesTreeEntry.pathto the matcher without a trailing separator, even when the entry is a directory. Abuild/pattern therefore misses thebuildentry itself. An emptybuilddirectory is omitted entirely bymatch_tree_entries().Reproduced on
masterat811bde1c624e85accee683b9cbf07c01538afacb:This uses the entry's cached
is_dir()result to append a separator to the normalized matching path, following the convention already used byappend_dir_sep(). It leaves the returned entries and their paths unchanged, avoids adding a second separator, and does not change the string-based matching APIs or traversal logic. The inheritedGitIgnoreSpecmethods receive the same fix.The regression tests reuse the existing backend matrix and filesystem helpers. They cover directory-only rules, empty directories, an ordinary file with the same name, exclusions,
negate=True, tree entry matching, unchanged file-only matching, returned object identity, and custom/already-present separators.Validation
Run locally on Windows with CPython 3.14.0 in a virtual environment. Both optional native backends were installed: google-re2 1.1.20251105 and hyperscan 0.8.2.
python -m unittest discover -t . -s tests/ -v: 223 tests, OK (14 skipped). All simple/re2/hyperscan configurations ran. The 14 skips are the existing Windows symlink tests; the unchanged baseline also skips them.python -m mypy pathspec tests/check_usage.py: passed (32 files).python -m sphinx -aWEnqb html doc/source doc/build: passed.python -m compileall -q pathspec tests,python -m tabnanny pathspec/pathspec.py tests/test_05_pathspec.py,python -m pip check, andgit diff --check: passed.python -m pyright pathspec tests/check_usage.py: not passing; six native-backend attribute-resolution errors. A clean worktree at the baseline produces the same six errors.ruff check --select F pathspec/pathspec.py tests/test_05_pathspec.py: not passing; seven existing test-file findings (one unused import and six placeholder-free f-strings), identical on the baseline. No unrelated cleanup is included.Other Python/OS combinations and the skipped symlink cases were not tested locally. No matching issue or PR was found, so the reproduction is included here without a separate issue.
AI assistance
An OpenAI Codex agent prepared this patch, reviewed the diff, and ran the commands above at the account owner's request. No human review or manual validation is claimed.