如果存储库是公共的,则推送到远程将引发异常。如果存储库是私有的,则相同的代码将起作用。第二次调用也会抛出 401 错误。可以使用命令行或 Sourcetree 推送。如何在公共存储库中使用 ligbit2sharp 进行推送?
例外:
{Name = "LibGit2SharpException" FullName = "LibGit2Sharp.LibGit2SharpException"} message="请求失败,状态码:401" innerException=null HResult=-2146233088
堆:
在 LibGit2Sharp.Core.Ensure.HandleError(Int32 结果) 在 LibGit2Sharp.Core.Proxy.git_remote_push(RemoteHandle remote, IEnumerable1 refSpecs, GitPushOptions opts) 在 LibGit2Sharp.Network.Push(Remote remote, IEnumerable1 pushRefSpecs, PushOptions pushOptions) 在 LibGit2Sharp.Network .Push(远程远程,IEnumerable`1 pushRefSpecs)在 LibGit2Sharp.Network.Push(远程远程,字符串 pushRefSpec)
版本:0.24.0.0 与 Visual Studio 2015
代码 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);
代码 2)
repo.Network.Push(remote, pushRefSpec);