Skip to content

Fetching from remote with explicit refspec raises error incorrectly #396

Closed

Description

@rrei

GitPython version: 1.0.2
File: git/remote.py
Line: 646
OS: Ubuntu 14.04LTS

Passing a refspec to git fetch through a remote, as in
repo.remotes.origin.fetch("+refs/heads/*:refs/remotes/origin/*")
will raise an error if the remote has no fetch refspec defined in the config:

AssertionError: Remote '%s' has no refspec set.
You can set it as follows: 'git config --add "remote.origin.fetch +refs/heads/*:refs/heads/*"'.

Also, note that the error message is incorrectly formatted because the remote's name is replaced only in the second line of the message (a %s appears in the first line of the final message).

The _assert_refspec() method should not be called if one or more refspecs were given as arguments to fetch().

Activity

  1. Byron commented on Mar 28, 2016

    @Byron
    Member

    Thanks for letting me know - the incorrectly formatted message should now be fixed.

    However, I am not quite sure why there is no 'fetch' configuration provided here. In a previous commit it is stated that gitpython needs this to work.

    Just not making the assertion should therefore result in a more difficult to debug error. Maybe you can try removing the assertion in question to see if GitPython will work anyway ?

  2. rrei commented on Mar 28, 2016

    @rrei
    ContributorAuthor

    I was testing this briefly and found out that the repo has no fetch refspec because I cloned it as a bare repo. Also, I commented the _assert_refspec() call, tried a fetch, and it worked like a charm.

    IPython 4.0.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    In [1]: import git
    
    In [2]: r = git.Repo.clone_from('git://example.com/repos/aletheia.git', 'aletheia.git', branch='develop', bare=True)
    
    In [3]: r.refs
    Out[3]: 
    [<git.Head "refs/heads/develop">,
     <git.Head "refs/heads/master">,
     <git.TagReference "refs/tags/0.1.0">]
    
    In [4]: r.remotes.origin.fetch('+refs/heads/*:refs/remotes/origin/*')
    Out[4]: 
    [<git.remote.FetchInfo at 0x7feb9e88a940>,
     <git.remote.FetchInfo at 0x7feb9e88a998>]
    
    In [5]: r.refs
    Out[5]: 
    [<git.Head "refs/heads/develop">,
     <git.Head "refs/heads/master">,
     <git.RemoteReference "refs/remotes/origin/develop">,
     <git.RemoteReference "refs/remotes/origin/master">,
     <git.TagReference "refs/tags/0.1.0">]
    

    So, I would be inclined to conclude that the assertion should only be made if no refspec argument is given:

    if refspec is None:
        self._assert_refspec()
    

    Are there any impediments to this change?

  3. added this to the milestone on Mar 28, 2016
  4. Byron commented on Mar 28, 2016

    @Byron
    Member

    If there are any impediments, then I don't see them.
    Would you be fine committing these changes and submit a PR ?

  5. rrei commented on Mar 28, 2016

    @rrei
    ContributorAuthor

    Sure, which branch would you like to fork from? (I'll be assuming it is "master" until I hear back from you)

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions