Skip to content

Fetching from remote with explicit refspec raises error incorrectly #396

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

Closed
rrei opened this issue Mar 14, 2016 · 4 comments
Closed

Fetching from remote with explicit refspec raises error incorrectly #396

rrei opened this issue Mar 14, 2016 · 4 comments

Comments

@rrei
Copy link
Contributor

rrei commented Mar 14, 2016

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().

Byron added a commit that referenced this issue Mar 28, 2016
@Byron
Copy link
Member

Byron commented Mar 28, 2016

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 ?

@rrei
Copy link
Contributor Author

rrei commented Mar 28, 2016

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?

@Byron Byron added this to the v1.0.3 - Fixes milestone Mar 28, 2016
@Byron
Copy link
Member

Byron commented Mar 28, 2016

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

@rrei
Copy link
Contributor Author

rrei commented Mar 28, 2016

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
Development

No branches or pull requests

2 participants