Skip to content

Index.add fail silently when path contains character [ #680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
olethanh opened this issue Oct 3, 2017 · 6 comments
Open

Index.add fail silently when path contains character [ #680

olethanh opened this issue Oct 3, 2017 · 6 comments

Comments

@olethanh
Copy link

olethanh commented Oct 3, 2017

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

@Byron
Copy link
Member

Byron commented Oct 4, 2017

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

@olethanh
Copy link
Author

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.

@Byron
Copy link
Member

Byron commented Dec 29, 2017

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

@olethanh
Copy link
Author

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

@sdementen
Copy link

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

@Byron
Copy link
Member

Byron commented Oct 14, 2018

@sdementen Review comments were added to the linked PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants