a Push to a remote will throw exception if repository is public. Same code will work if repository is private. The second call will also throw 401 error. Push with commandline or Sourcetree is possible. How will push work with ligbit2sharp with public repositories?
Exception:
{Name = "LibGit2SharpException" FullName = "LibGit2Sharp.LibGit2SharpException"} message="request failed with status code: 401" innerException=null HResult=-2146233088
Stack:
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) at LibGit2Sharp.Core.Proxy.git_remote_push(RemoteHandle remote, IEnumerable1 refSpecs, GitPushOptions opts) at LibGit2Sharp.Network.Push(Remote remote, IEnumerable1 pushRefSpecs, PushOptions pushOptions) at LibGit2Sharp.Network.Push(Remote remote, IEnumerable`1 pushRefSpecs) at LibGit2Sharp.Network.Push(Remote remote, String pushRefSpec)
Version: 0.24.0.0 with Visual Studio 2015
Code 1)
CredentialsHandler newt =
new CredentialsHandler((url, fromUrl, types) =>
new UsernamePasswordCredentials { Username = userName, Password = userPass });
var options = new PushOptions();
options.CredentialsProvider = newt;
options.OnPackBuilderProgress = packBuilderProgressHandler;
options.OnPushTransferProgress = pushTransferProgressHandler;
options.OnPushStatusError = pushStatusErrorHandler;
repo.Network.Push(
repo.Network.Remotes["origin"],
@"refs/heads/master:refs/heads/master",
options);
Code 2)
repo.Network.Push(remote, pushRefSpec);