Dan*_*ett 2 c# git github libgit2 libgit2sharp
我正在尝试连接到一个回购:
using(var Git = new Repository(
Repository.Clone("https://github.com/wikimedia/mediawiki-core", "tmp")
)){
foreach(var Commit in Git.Commits)
{
MessageBox.Show(Commit.Author.Name);
}
}
Run Code Online (Sandbox Code Playgroud)
它连接正常(如果我更改了URL,我得到了预期的异常),但没有显示MessageBoxes - 为什么?这应该很简单.
关于您的问题,您需要考虑以下几点:
Repository.Clone())然后执行针对本地存储库的一些工作.Clone()方法提供传输进度处理程序,可以获得有关克隆进度的一些见解.下面的代码(极大地受到您自己的代码的启发)克隆了一个远程存储库,将当前克隆进程输出到控制台,并枚举了可从中获取的提交HEAD.
它已成功通过LibGit2Sharp v0.14.1 NuGet包进行测试.
public void CloneAndEnumerateCommitsFromHead()
{
var tmp = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
string path = Repository.Clone(
"https://github.com/nulltoken/TestGitRepository",
tmp,
onTransferProgress: ProgressHandler);
using (var Git = new Repository(path))
{
foreach (var Commit in Git.Commits)
{
Console.WriteLine("{0} by {1}",
Commit.Id.ToString(7),
Commit.Author.Name);
}
}
}
private int ProgressHandler(TransferProgress progress)
{
Console.WriteLine("{0}/{1}", progress.IndexedObjects, progress.TotalObjects);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
运行时,输出以下内容
0/70
1/70
2/70
2/70
...snipped for brevity...
68/70
69/70
70/70
70/70
49322bb by A U Thor
d0114ab by A U Thor
f73b956 by A U Thor
6e14752 by A U Thor
1203b03 by A U Thor
bab66b4 by A U Thor
83834a7 by A U Thor
6462e7d by A U Thor
42e4e7c by A U Thor
7f82283 by A U Thor
59706a1 by A U Thor
c070ad8 by A U Thor
d31f5a6 by A U Thor
83d2f04 by A U Thor
6db9c2e by A U Thor
d86a2aa by A U Thor
0966a43 by A U Thor
2c34933 by A U Thor
ac7e7e4 by A U Thor
58be465 by A U Thor
6c8b137 by A U Thor
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3186 次 |
| 最近记录: |