Skip to content

Fetching a remote without a configured refspec raises ValueError #296

Closed
@earwig

Description

@earwig

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

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions