LibGit2Sharp获取远程存储库的最新版本

时间:2017-11-16 10:56:28

标签: c# libgit2sharp

我想在我的winforms项目中跟踪一个使用git的项目。我不想克隆完整的存储库和完整的历史记录,我只想要最新的版本,我希望能够从远程项目更新到新版本。

我试过这个

co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = userName, Password = passWord };

        Repository.Clone("Git/repo", @tmpRepoFolder, co);

,但这会创建整个存储库的副本(巨大的文件大小),并且跟踪更改会使磁盘空间更大(100mb的文件现在占用超过2GB)。

我不需要历史,也不需要标签。我只想要最新版本。

1 个答案:

答案 0 :(得分:0)

基本上你想要一个实际上不受支持的克隆(相当于git clone --depth命令),那里有一个开放的issue

作为替代方案,您可以启动一个使用git应用程序执行所需操作的进程。

这是一个例子:

using(System.Diagnostics.Process p = new Process())
{
    p.StartInfo = new ProcessStartInfo()
    {
        RedirectStandardInput = true,
        RedirectStandardOutput = true,
        UseShellExecute = false,
        FileName = @"C:\Program Files\Git\bin\git.exe",
        Arguments = "clone http://username:password@path/to/repo.git"  + " --depth 1"                
    };

    p.Start();
    string output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();
}
相关问题