bitranox / igittigitt

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

issue with negates pattern #19

Open penja opened 3 years ago

penja commented 3 years ago
import igittigitt
"""
Based on https://git-scm.com/docs/gitignore#_examples
Example to exclude everything except a specific directory foo/bar 
(note the /* - without the slash, the wildcard would also exclude everything within foo/bar):
 $ cat .gitignore
    # exclude everything except directory foo/bar
    /*
    !/foo
    /foo/*
    !/foo/bar
"""

gitignore = igittigitt.IgnoreParser()
base_path = "/example/"
gitignore.add_rule("/*", base_path)
gitignore.add_rule("!/foo", base_path)
gitignore.add_rule("/foo/*", base_path)
gitignore.add_rule("!/foo/bar", base_path)
assert gitignore.match(base_path + "foo/bar/file.txt") == False
assert gitignore.match(base_path + "foo/other/tile.txt") == True #failed on current version
bitranox commented 3 years ago

interesting. I will look after it, but it will take some (longer) time. thank You for the bug report !

penja commented 3 years ago

I guess that problem here https://github.com/bitranox/igittigitt/blob/master/igittigitt/igittigitt.py#L311 The value returned based first matched rule and other rules don't take into consideration

Thank you for the answer and future fix.

bitranox commented 2 years ago

unfortunately You are absolutely right - and this is not the only problem. basically the handling of multiple ignore files, precedence levels and so on, is just very wrong in igittigitt. It is not that difficult to fix, but many parts needs to be plumbed together in a different way.

the documentation at https://git-scm.com/docs/gitignore#_pattern_format is not very accurate or complete - luckily I found some better explenation here :

see : struct_walker

I will put a comment in the readme about that issue in the meantime.