如何从Git的使用LibGit2Sharp抓取的变化? [英] How to fetch change from Git using LibGit2Sharp?

查看:970
本文介绍了如何从Git的使用LibGit2Sharp抓取的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面克隆的code一个Git url到test目录。

The code below clone a Git url to a test directory.

var url = @"http://abc-555.com/team/project-555.git";
var path = @"E:\temp_555";

var credential =  new Credentials() { Username = "a8888", Password="88888888"};
var clonePath = Repository.Clone(url, path, credentials: credential);

using (var repo = new Repository(clonePath))
{
    foreach (var branch in repo.Branches)
    {
        Console.WriteLine(branch.Name);
    }

    // somebody creates a new branch here, so I want to fetch it.
    repo.Fetch("origin");

    foreach (var branch in repo.Branches)
    {
        Console.WriteLine(branch.Name);
    }
}

我希望它合并到本地的Git之前获取一个新的分支。无论如何,它抛出错误上调libgit2。类别=净(错误)。请求失败,状态为code:401 除了

如何解决这一问题?

推荐答案

您,可以指定要通过的 FetchOptions 实例作为最后一个参数电话。

You can specifiy the credentials to be used through a FetchOptions instance as the last parameter of the Fetch call.

repo.Fetch("origin", new FetchOptions { Credentials = credential});

这篇关于如何从Git的使用LibGit2Sharp抓取的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆