使用公共存储库

时间:2018-04-10 15:29:48

标签: git libgit2sharp gogs

如果存储库是公共的,则推送到远程将抛出异常。如果存储库是私有的,则相同的代码第二次调用也会抛出401错误。可以使用命令行或Sourcetree进行推送。如何推动ligbit2sharp与公共存储库一起工作?

例外:

  

{Name =“LibGit2SharpException”FullName =   “LibGit2Sharp.LibGit2SharpException”} message =“请求失败   状态码:401“innerException = null HResult = -2146233088

堆栈:

  

at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)at   LibGit2Sharp.Core.Proxy.git_remote_push(RemoteHandle远程,   IEnumerable1 refSpecs,GitPushOptions opts)at   LibGit2Sharp.Network.Push(远程远程,IEnumerable1 pushRefSpecs,   PushGptions pushOptions)在LibGit2Sharp.Network.Push(远程远程,   在LibGit2Sharp.Network.Push(Remote,IEnumerable`1 pushRefSpecs)   remote,String pushRefSpec)

版本: 使用Visual Studio 2015获得0.24.0.0

代码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);

0 个答案:

没有答案
相关问题