GitPython icon indicating copy to clipboard operation
GitPython copied to clipboard

Index.add fail silently when path contains character `[`

Open olethanh opened this issue 8 years ago • 6 comments

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

olethanh avatar Oct 03 '17 13:10 olethanh

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

Byron avatar Oct 04 '17 04:10 Byron

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 avatar Dec 28 '17 13:12 olethanh

@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)?

Byron avatar Dec 29 '17 14:12 Byron

Yes, that's the workaround we used in our project in the end.

olethanh avatar Dec 31 '17 16:12 olethanh

in the PR, if a path with glob characters exists as such, it is also yielded

sdementen avatar Sep 18 '18 03:09 sdementen

@sdementen Review comments were added to the linked PR.

Byron avatar Oct 14 '18 10:10 Byron