Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_1.in.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Bug fixes:
- `Issue #176`_: Normalize redundant interior separators and current-directory components in matching paths, preserving original paths in matching results.
- `Issue #177`_: Preserve slashes inside gitignore bracket expressions while excluding path separators from their matches.
- `Pull #180`_: - Treat a negated root-only gitignore pattern (``!/``) as a no-op instead of re-including directories.
- A directory pattern ending in a run of three or more asterisks (e.g., ``d/***/``) now requires a descendant directory like ``d/**/``, so it no longer matches ``d/`` or its direct files.


.. _`Issue #116`: https://github.com/cpburnz/python-pathspec/issues/116
Expand Down
10 changes: 6 additions & 4 deletions pathspec/patterns/gitignore/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,14 @@ def pattern_to_regex(

# A terminal directory globstar with a concrete prefix must consume a
# descendant segment before the directory marker. Keep this semantic bit
# separate from normalized segments, which collapse adjacent ``**``.
# separate from normalized segments, which collapse adjacent ``**``. A run
# of three or more asterisks is a globstar too (e.g., ``d/***/``).
star_segs = _collapse_star_runs(orig_segs)
requires_dir_descendant = (
is_dir_pattern
and len(orig_segs) > 2
and orig_segs[-2] == '**'
and any(seg not in ('', '**') for seg in orig_segs[:-2])
and len(star_segs) > 2
and star_segs[-2] == '**'
and any(seg not in ('', '**') for seg in star_segs[:-2])
)

# Normalize pattern to make processing easier.
Expand Down
22 changes: 22 additions & 0 deletions tests/test_06_gitignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,28 @@ def test_c(self):
{"top.txt", "d/"},
{"d/top.txt", "d/child/", "a/b/deep.txt"},
),
# A run of three or more asterisks is a globstar, so these behave like
# the "**" patterns above.
(
"d/***/",
{"d/", "d/top.txt"},
{"d/child/", "d/child/file.txt", "d/child/grandchild/deep.txt"},
),
(
"/d/****/",
{"d/", "d/top.txt"},
{"d/child/", "d/child/file.txt"},
),
(
"**/d/***/",
{"d/top.txt", "x/d/", "x/d/top.txt"},
{"d/child/file.txt", "x/d/child/file.txt"},
),
(
"a/**/***/",
{"a/", "a/top.txt"},
{"a/child/", "a/child/file.txt", "a/b/top.txt"},
),
]
for pattern, unignored, ignored in cases:
for sub_test in self.parameterize_from_lines([pattern]):
Expand Down