Closed
Description
I found this easiest to reproduce by creating a bare clone of another repository.
Set up like this:
ben@earwig:~/test $ git init foo
Initialized empty Git repository in /Users/ben/test/foo/.git/
ben@earwig:~/test $ cd foo
ben@earwig:~/test/foo [master] $ echo "test" > test && git add test && git commit -m "test"
[master (root-commit) 269c498] test
1 file changed, 1 insertion(+)
create mode 100644 test
ben@earwig:~/test/foo [master] $ cd ..
ben@earwig:~/test $ git clone --bare foo bar
Cloning into bare repository 'bar'...
done.
Note the structure of the config
file and that an ordinary git fetch origin
works.
ben@earwig:~/test $ cd bar
ben@earwig:~/test/bar [BARE:master] $ cat config
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = /Users/ben/test/foo
ben@earwig:~/test/bar [BARE:master] $ git fetch origin
From /Users/ben/test/foo
* branch HEAD -> FETCH_HEAD
Now, here's the bug:
ben@earwig:~/test/bar [BARE:master] $ python
Python 2.7.10 (default, May 29 2015, 21:05:23)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> git.Repo().remotes.origin.fetch()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/git/remote.py", line 651, in fetch
res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
File "/usr/local/lib/python2.7/site-packages/git/remote.py", line 588, in _get_fetch_info_from_stderr
for err_line, fetch_line in zip(fetch_info_lines, fetch_head_info))
File "/usr/local/lib/python2.7/site-packages/git/remote.py", line 588, in <genexpr>
for err_line, fetch_line in zip(fetch_info_lines, fetch_head_info))
File "/usr/local/lib/python2.7/site-packages/git/remote.py", line 249, in _from_line
raise ValueError("Failed to parse FETCH_HEAD line: %r" % fetch_line)
ValueError: Failed to parse FETCH_HEAD line: u'269c498e56feb93e408ed4558c8138d750de8893\t\t/Users/ben/test/foo\n'
>>>
If I add a valid refspec to the config, it works:
ben@earwig:~/test/bar [BARE:master] $ git config --add remote.origin.fetch +refs/heads/*:refs/heads/*
ben@earwig:~/test/bar [BARE:master] $ python
Python 2.7.10 (default, May 29 2015, 21:05:23)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import git
>>> git.Repo().remotes.origin.fetch()
[<git.remote.FetchInfo object at 0x11094a0a8>]
>>>
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
Byron commentedon Jun 10, 2015
Thanks for the report !
I fixed the issue by explicitly checking for the case and tell the user a refspec is required for gitpython to work.
Byron commentedon Jun 10, 2015
You can watch the development stream on youtube.
GitPython #8 [issue 296 - handle missing fetch-refspec gracefully]
kshpytsya commentedon Dec 24, 2018
For me, a new user of
GitPython
, it is unclear, whyrefspec
is required in this situation while it is unneeded by vanilla git. Maybe a couple of words in the docs are due, or have I missed them?My current use case for
GitPython
is very simple: I need to be able to access specific files from specific revision of some repository.On the second run, this fails with
I have fixed this by replacing
with
however, I am not sure if it is correct.