0

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);
  • To clarify, your code snippet 1 works if the same repository is set to private? But as soon as the repository is set to public, it stops working and returns a 401? – Edward Thomson Apr 10 '18 at 15:51
  • That's right. If the repository is set to private Code Snippet 1 works. After setting repository to public the same code does not work. Setting it to private again will work again. – SoftwareArchitec Apr 11 '18 at 05:16

0 Answers0