Skip to content
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

Fetch with url throws "not a valid remote name". #1488

Open
VoronFX opened this issue Sep 3, 2017 · 7 comments
Open

Fetch with url throws "not a valid remote name". #1488

VoronFX opened this issue Sep 3, 2017 · 7 comments

Comments

@VoronFX
Copy link

VoronFX commented Sep 3, 2017

Nothing much to tell, fetch with url is not working.

Example:

Repository.Network.Fetch("https://github.com/libgit2/libgit2sharp.git", new[] { "+refs/remotes/test:refs/heads/master" });

Exception:
InvalidSpecificationException: 'https://github.com/libgit2/libgit2sharp.git' is not a valid remote name.

@ethomson
Copy link
Member

ethomson commented Sep 3, 2017

It's not supposed to; you can't fetch with a URL. Set up a remote with that URL, then specify the remote name that you've configured.

@ethomson ethomson closed this as completed Sep 3, 2017
@VoronFX
Copy link
Author

VoronFX commented Sep 3, 2017

It is supported by libgit2 and I think it's nice feature cause I don't need to setup remote for one time operations. Of course you may not support it, but then it's probably better to change those confusing parameter names and descriptions:

//
// Summary:
//     Fetch from a url with a set of fetch refspecs
//
// Parameters:
//   url:
//     The url to fetch from
//
//   refspecs:
//     The list of resfpecs to use
//
//   options:
//     LibGit2Sharp.FetchOptions controlling fetch behavior
//
//   logMessage:
//     Message to use when updating the reflog.
public virtual void Fetch(string url, IEnumerable<string> refspecs, FetchOptions options, string logMessage);

@ethomson
Copy link
Member

ethomson commented Sep 3, 2017

Really! I actually didn't know that. What's the API for this in libgit2?

@VoronFX
Copy link
Author

VoronFX commented Sep 3, 2017

Ah sorry, my bad, I've mixed up the docs from git itself and libgit2. Then no complain, but the names still better to fix sometime.

@ethomson
Copy link
Member

ethomson commented Sep 3, 2017

Okay, thanks for the clarification. I definitely agree with that. I'm going to reopen to make sure that we take care of that. Thanks!

@chescock
Copy link
Contributor

I just hit this error after an update, so I think this is something that LibGit2Sharp used to support.

Looking through the history, I think it broke with #1288. The old version of Fetch had separate overloads that called git_remote_lookup when given a Remote and git_remote_create_anonymous when given a string. The new version first tries git_remote_lookup, and if that returns null then it calls git_remote_create_anonymous.

But URLs contain slashes, and remote names may not contain slashes, so passing a URL to the native git_remote_lookup returns GitErrorCode.InvalidSpecification instead of GitErrorCode.NotFound. That causes Proxy.git_remote_lookup to throw an exception instead of returning null, so the code never reaches the call to git_remote_create_anonymous.

@Ranjankumarrj
Copy link

Ranjankumarrj commented Jul 28, 2020

git remote add https-//github.com/Ranjanudt/LatestOfferScreen.git LatestOfferScreen
fatal: 'https-//github.com/Ranjanudt/LatestOfferScreen.git' is not a valid remote name

just put (git remote add origin) after https link pastes it.

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

No branches or pull requests

4 participants