Skip to content

Commit

Permalink
Issue 64
Browse files Browse the repository at this point in the history
  • Loading branch information
cpburnz committed Nov 12, 2022
1 parent 269502b commit 2bfe91b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Bug fixes:
- Type hint on *root* parameter on `pathspec.pathspec.PathSpec.match_tree_files()`.
- Type hint on *root* parameter on `pathspec.util.iter_tree_entries()`.
- Type hint on *root* parameter on `pathspec.util.iter_tree_files()`.
- WIP: `Issue #64`_: IndexError with my .gitignore file when trying to build a Python package.
- `Issue #64`_: IndexError with my .gitignore file when trying to build a Python package.

Improvements:

Expand Down
1 change: 1 addition & 0 deletions pathspec/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"jack1142 <https://github.com/jack1142>",
"mgorny <https://github.com/mgorny>",
"bzakdd <https://github.com/bzakdd>",
"haimat <https://github.com/haimat>",
]
__license__ = "MPL 2.0"
__version__ = "0.10.2.dev1"
2 changes: 1 addition & 1 deletion pathspec/patterns/gitwildmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def pattern_to_regex(
if i == 0 and i == end:
# A pattern consisting solely of double-asterisks ('**')
# will match every path.
output.append('.+')
output.append(f'[^/]+(?:(?P<{_DIR_MARK}>/).*)?')
elif i == 0:
# A normalized pattern beginning with double-asterisks
# ('**') will match any leading path segments.
Expand Down
20 changes: 20 additions & 0 deletions tests/test_gitignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,23 @@ def test_05_issue_39(self):
'important/d.log',
'important/e.txt',
})

def test_06_issue_64(self):
"""
Test using a double asterisk pattern.
"""
spec = GitIgnoreSpec.from_lines([
"**",
])
files = {
'x',
'y.py',
'A/x',
'A/y.py',
'A/B/x',
'A/B/y.py',
'A/B/C/x',
'A/B/C/y.py',
}
ignores = set(spec.match_files(files))
self.assertEqual(ignores, files)
28 changes: 25 additions & 3 deletions tests/test_gitwildmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
This regular expression matches the directory marker.
"""

RE_SUB = f"(?:(?P<{_DIR_MARK}>/).*)?"
RE_SUB = f"(?:{RE_DIR}.*)?"
"""
This regular expression matches an optional sub-path.
"""
Expand Down Expand Up @@ -258,7 +258,29 @@ def test_03_only_double_asterisk(self):
"""
regex, include = GitWildMatchPattern.pattern_to_regex('**')
self.assertTrue(include)
self.assertEqual(regex, '^.+$')
self.assertEqual(regex, f'^[^/]+{RE_SUB}$')
pattern = GitWildMatchPattern(re.compile(regex), include)
results = set(filter(pattern.match_file, [
'x',
'y.py',
'A/x',
'A/y.py',
'A/B/x',
'A/B/y.py',
'A/B/C/x',
'A/B/C/y.py',
]))

self.assertEqual(results, {
'x',
'y.py',
'A/x',
'A/y.py',
'A/B/x',
'A/B/y.py',
'A/B/C/x',
'A/B/C/y.py',
})

def test_03_parent_double_asterisk(self):
"""
Expand Down Expand Up @@ -292,7 +314,7 @@ def test_03_duplicate_leading_double_asterisk_edge_case(self):
"""
regex, include = GitWildMatchPattern.pattern_to_regex('**')
self.assertTrue(include)
self.assertEqual(regex, '^.+$')
self.assertEqual(regex, f'^[^/]+{RE_SUB}$')

equivalent_regex, include = GitWildMatchPattern.pattern_to_regex('**/**')
self.assertTrue(include)
Expand Down

0 comments on commit 2bfe91b

Please sign in to comment.