|
14 | 14 | _BYTES_ENCODING) |
15 | 15 | from pathspec.patterns.gitignore.spec import ( |
16 | 16 | GitIgnoreSpecPattern, |
| 17 | + _DIR_MARK, |
17 | 18 | _DIR_MARK_CG, |
18 | | - _DIR_MARK_OPT) |
| 19 | + _DIR_MARK_OPT, |
| 20 | + _MATCH_ALL) |
19 | 21 | from pathspec.patterns.gitwildmatch import ( |
20 | 22 | GitWildMatchPattern) |
21 | 23 | from pathspec.util import ( |
@@ -275,7 +277,7 @@ def test_03_only_double_asterisk(self): |
275 | 277 | """ |
276 | 278 | regex, include = GitIgnoreSpecPattern.pattern_to_regex('**') |
277 | 279 | self.assertTrue(include) |
278 | | - self.assertEqual(regex, '.') |
| 280 | + self.assertEqual(regex, _MATCH_ALL) |
279 | 281 |
|
280 | 282 | pattern = GitIgnoreSpecPattern(re.compile(regex), include) |
281 | 283 | results = set(filter(pattern.match_file, [ |
@@ -332,7 +334,7 @@ def test_03_duplicate_leading_double_asterisk_edge_case(self): |
332 | 334 | """ |
333 | 335 | regex, include = GitIgnoreSpecPattern.pattern_to_regex('**') |
334 | 336 | self.assertTrue(include) |
335 | | - self.assertEqual(regex, '.') |
| 337 | + self.assertEqual(regex, _MATCH_ALL) |
336 | 338 |
|
337 | 339 | equiv_regex, include = GitIgnoreSpecPattern.pattern_to_regex('**/**') |
338 | 340 | self.assertTrue(include) |
@@ -753,7 +755,23 @@ def test_12_asterisk_1_regex(self): |
753 | 755 | """ |
754 | 756 | regex, include = GitIgnoreSpecPattern.pattern_to_regex('*') |
755 | 757 | self.assertTrue(include) |
756 | | - self.assertEqual(regex, '.') |
| 758 | + self.assertEqual(regex, _MATCH_ALL) |
| 759 | + |
| 760 | + def test_12_asterisk_1b_regex_marks_directories(self): |
| 761 | + """ |
| 762 | + Test that the relative asterisk path pattern captures the directory marker. |
| 763 | +
|
| 764 | + Without the marker, "*" outranks a later directory-only pattern (e.g. |
| 765 | + "!*/") and :class:`.GitIgnoreSpec` reports a directory as ignored where Git |
| 766 | + does not. |
| 767 | + """ |
| 768 | + regex, include = GitIgnoreSpecPattern.pattern_to_regex('*') |
| 769 | + self.assertTrue(include) |
| 770 | + |
| 771 | + compiled = re.compile(regex) |
| 772 | + self.assertIsNotNone(compiled.search('dirA/').group(_DIR_MARK)) |
| 773 | + self.assertIsNone(compiled.search('fileA').group(_DIR_MARK)) |
| 774 | + self.assertIsNone(compiled.search('dirA/fileB').group(_DIR_MARK)) |
757 | 775 |
|
758 | 776 | def test_12_asterisk_2_regex_equivalent(self): |
759 | 777 | """ |
|
0 commit comments