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

Proxy.git_remote_connect() hides exceptions #1912

Closed
YuKitsune opened this issue Sep 20, 2021 · 2 comments · Fixed by #1913
Closed

Proxy.git_remote_connect() hides exceptions #1912

YuKitsune opened this issue Sep 20, 2021 · 2 comments · Fixed by #1913

Comments

@YuKitsune
Copy link
Contributor

YuKitsune commented Sep 20, 2021

I've noticed when calling Repository.ListRemoteReferences with a URL that doesn't point to a valid git repo, I get a fairly unhelpful error:

LibGit2Sharp.LibGit2SharpException: this remote has never connected
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_ls(Repository repository, RemoteHandle remote)
   at LibGit2Sharp.Repository.ListRemoteReferences(String url, CredentialsHandler credentialsProvider)
   at LibGit2Sharp.Repository.ListRemoteReferences(String url)
   at LibGit2SharpScratchpad.Program.Main(String[] args)

I did some digging and noticed in Repository.ListRemoteReferences(string, CredentialsHandler), there is a call to git_remote_connect, then git_remote_ls. In git_remote_connect, if an exception is thrown (E.g: from the call to Ensure.ZeroResult(res)), it's caught and then ignored:

public static unsafe void git_remote_connect(RemoteHandle remote, GitDirection direction, ref GitRemoteCallbacks remoteCallbacks, ref GitProxyOptions proxyOptions)
{
GitStrArrayManaged customHeaders = new GitStrArrayManaged();
try
{
int res = NativeMethods.git_remote_connect(remote, direction, ref remoteCallbacks, ref proxyOptions, ref customHeaders.Array);
Ensure.ZeroResult(res);
}
catch (Exception)
{
customHeaders.Dispose();
}
}

It looks like this was introduced in this commit: 6bc517f

Because this doesn't re-throw the exception, git_remote_ls gets given a null transport, and thus throws the this remote has never connected error.

I would've expected this to re-throw the exception after disposing of the custom headers.

Seems like an easy fix and I'm happy to send through a PR, just wondering if this was intentional or a legitimate bug.

@YuKitsune YuKitsune changed the title Proxy. git_remote_connect() hides exceptions Proxy.git_remote_connect() hides exceptions Sep 20, 2021
@ethomson
Copy link
Member

Yes, this looks like an error!

@YuKitsune
Copy link
Contributor Author

Thanks for checking @ethomson
I've raised a PR: #1913

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

Successfully merging a pull request may close this issue.

2 participants