bitranox / igittigitt

A spec-compliant gitignore parser for Python
MIT License
24 stars 6 forks source link

not parsing subdirs of ignored directories #10

Closed mdolling-gfz closed 4 years ago

mdolling-gfz commented 4 years ago

If behavior is intended, I need support, if not, it might be a bug

Currently files in subdirectories of ignored directories are not matched.

rule in .gitignore: src_old/ file not matched: src_old/foo/bar.py

.gitignore

src_old/
.idea/

code

import igittigitt
import pprint
import pathlib

current_path = pathlib.Path(__file__).parent.absolute()

gitignore_parser = igittigitt.IgnoreParser()
gitignore_parser.parse_rule_files(current_path)

pp = pprint.PrettyPrinter(indent=4)
pp.pprint(gitignore_parser.rules)

print(gitignore_parser.match(pathlib.Path(f'{current_path}/src_old')))
print(gitignore_parser.match(pathlib.Path(f'{current_path}/src_old/foo.py')))
print(gitignore_parser.match(pathlib.Path(f'{current_path}/src_old/foo')))
print(gitignore_parser.match(pathlib.Path(f'{current_path}/src_old/foo/bar.py')))

output

[   IgnoreRule(pattern_fnmatch='/home/md/PycharmProjects/test/**/.idea', pattern_original='.idea/', is_negation_rule=False, source_file=PosixPath('/home/md/PycharmProjects/test/.gitignore'), source_line_number=2),
    IgnoreRule(pattern_fnmatch='/home/md/PycharmProjects/test/**/.idea/*', pattern_original='.idea/', is_negation_rule=False, source_file=PosixPath('/home/md/PycharmProjects/test/.gitignore'), source_line_number=2),
    IgnoreRule(pattern_fnmatch='/home/md/PycharmProjects/test/**/src_old', pattern_original='src_old/', is_negation_rule=False, source_file=PosixPath('/home/md/PycharmProjects/test/.gitignore'), source_line_number=1),
    IgnoreRule(pattern_fnmatch='/home/md/PycharmProjects/test/**/src_old/*', pattern_original='src_old/', is_negation_rule=False, source_file=PosixPath('/home/md/PycharmProjects/test/.gitignore'), source_line_number=1),
    IgnoreRule(pattern_fnmatch='/home/md/PycharmProjects/test/.idea', pattern_original='.idea/', is_negation_rule=False, source_file=PosixPath('/home/md/PycharmProjects/test/.gitignore'), source_line_number=2),
    IgnoreRule(pattern_fnmatch='/home/md/PycharmProjects/test/.idea/*', pattern_original='.idea/', is_negation_rule=False, source_file=PosixPath('/home/md/PycharmProjects/test/.gitignore'), source_line_number=2),
    IgnoreRule(pattern_fnmatch='/home/md/PycharmProjects/test/src_old', pattern_original='src_old/', is_negation_rule=False, source_file=PosixPath('/home/md/PycharmProjects/test/.gitignore'), source_line_number=1),
    IgnoreRule(pattern_fnmatch='/home/md/PycharmProjects/test/src_old/*', pattern_original='src_old/', is_negation_rule=False, source_file=PosixPath('/home/md/PycharmProjects/test/.gitignore'), source_line_number=1)]
True
True
True
False

Every subdir and file in subdirs of a ignored dir should be matched.

in 1.0.6 it was matching all sub* of a ignored directory

bitranox commented 4 years ago

thanks for the report - I will look into it.

bitranox commented 4 years ago

I just released a new version which should correct the bug. Please let me know if You find more issues !

bitranox commented 4 years ago

oops, just discovered that it was still not correctly working after adding some more tests. From version 2.0.2 it should work, will release it just now. Robert