igittigitt icon indicating copy to clipboard operation
igittigitt copied to clipboard

issue with negates pattern

Open penja opened this issue 4 years ago • 3 comments

  • **I'm submitting a ... **

    • [x] bug report
    • [ ] feature request
    • [ ] support request
  • What is the current behavior? Based on gitignore specification it is not possible to re-include a file if a parent directory of that file is excluded. https://git-scm.com/docs/gitignore#_pattern_format I try to exclude specific directory based on example

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
  • **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
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
  • What is the expected behavior? Based above example gitignore.match(base_path + "foo/other/tile.txt") should return True

  • Please tell us about your environment:

  • Release Number of the Repository used : 2.0.4
  • Python Version : 3.8.6
  • OS, OS Version : MacOS

penja avatar Mar 31 '21 12:03 penja

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

bitranox avatar Mar 31 '21 21:03 bitranox

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.

penja avatar Apr 01 '21 07:04 penja

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.

bitranox avatar Nov 19 '21 22:11 bitranox