Skip to content
Merged
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 @@ -61,6 +61,7 @@ Bug fixes:
- `Pull #182`_: Preserve subclass state when shallow-copying regular expression patterns, including subclasses without an include parameter.
- `Pull #184`_: Preserve overridden `RegexPattern.match_file()` implementations when selecting a backend.
- `Pull #188`_: Treat a trailing `**\` as an invalid gitignore pattern.
- 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 #192`_ / `Pull #193`_: Pattern `[z-a]` raises re.error, Git accepts the pattern.

.. _`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 @@ -1131,6 +1131,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