Index.add fail silently when path contains character `[`
Hello,
on windows when the path passed as an argument given to index.add contains a [, the function just return an empty list, whether or not the path exists.
r = git.Repo('.')
r.index.add(['test[test'])
Out[88]: []
Kind Regards and thanks for this project
Thanks for creating this ticket and for providing some steps to reproduce it right away.
Even though I didn’t reproduce the issue yet as I am on an iPad, and thus acknowledge it in good faith, I wonder if you tried it on non-windows already.
In any case, if you could write a test for the issue (probably in test_index.py), it should be easy for you to even provide a fix. However, a PR with a test would already be helping and appreciated.
Many thanks
Have not written the test yet but I have managed to reproduce it on Linux (Ubuntu 17.04)
Here are the steps In bash
mkdir tmp
cd tmp
git init .
mkdir test\[test\]
touch test\[test\]/test
pip freeze|grep GitPython
# GitPython==2.1.8
git --version
# git version 2.14.1
In python:
fn = 'test[test]/test'
open(fn) # working
import git
r = git.Repo('.')
r.index.add([fn])
# -> []
# With glob.escape (python3 only)
import glob
glob.escape(fn) # 'test[[]test]/test'
r.index.add([glob.escape(fn)])
# -> [] still empty
A colleague suggested this may be due to the way you use glob.
@olethanh Thanks a lot for making the issue more approachable! Do you think that as a workaround, it's possible to use git directly, such as in r.git.add(fn)?
Yes, that's the workaround we used in our project in the end.
in the PR, if a path with glob characters exists as such, it is also yielded
@sdementen Review comments were added to the linked PR.