GitPython icon indicating copy to clipboard operation
GitPython copied to clipboard

Inconsistent Tree.__contains__ / Tree.__getitem__ behaviour

Open ei-grad opened this issue 5 years ago • 2 comments

The fe5289ed introduced the Tree.__contains__ behaviour change, which is inconsistent with Tree.__getitem__ behaviour. I couldn't find a proper explanation for a such change, so it looks like a bug for me:

ipdb> p tree.path                                                                                                                                                                                                   
'data_dir'
ipdb> p [i.name for i in tree]                                                                                                                                                                                      
['data_sub_dir']
ipdb> p tree['data_sub_dir']                                                                                                                                                                                        
<git.Tree "43420912747f332d8bbd0859003a032a301ebbd6">
ipdb> p 'data_sub_dir' in tree                                                                                                                                                                                      
False
ipdb> p 'data_dir/data_sub_dir' in tree                                                                                                                                                                             
True

Not sure if this could be fixed now due to compatibility reasons, but if so, could there be a better workaround than iterating over Tree._cache?

ei-grad avatar Mar 08 '19 15:03 ei-grad

Thanks for bringing this up! It's a bit disturbing to see the referenced commit was created by me just... 9 years ago!

To me, it also looks like a bug! The behaviour I would expect is 'data_sub_dir' in tree to be true and the other one to be false.

Byron avatar Jul 20 '19 06:07 Byron

any ideas how to address the cache issue ?

bazilek avatar Apr 13 '20 17:04 bazilek