我正在尝试从本地文件系统克隆 git 存储库:
using System;
using LibGit2Sharp;
class Program
{
static void Main()
{
var sourceUrl = @"file:///c:/work/libgit2sharp";
using (Repository.Clone(sourceUrl, "targetDir", bare: true))
{
Console.WriteLine("repository successfully cloned");
}
}
}
我得到一个例外:
Unhandled Exception: LibGit2Sharp.LibGit2SharpException: An error was raised by libgit2. Category = Odb (Error).
Failed to find the memory window file to deregister
at LibGit2Sharp.Core.Ensure.Success(Int32 result, Boolean allowPositiveResult) in c:worklibgit2sharpLibGit2SharpCoreEnsure.cs:line 85
at LibGit2Sharp.Core.Proxy.git_clone_bare(String url, String workdir, git_transfer_progress_callback transfer_cb) in c:worklibgit2sharpLibGit2SharpCoreProxy.cs:line 219
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, Boolean bare, Boolean checkout, TransferProgressHandler onTransferProgress, CheckoutProgressHandler onCheckoutProgress) in c:worklibgit2sharpLibGit2SharpRepository.cs:line 431
at Program.Main() in c:workConsoleApplication1Program.cs:line 10
我还尝试了以下源网址:
var sourceUrl = @"c:worklibgit2sharp.git";
并得到了另一个例外:
Unhandled Exception: LibGit2Sharp.LibGit2SharpException: An error was raised by libgit2. Category = Config (Error).
Failed to parse config file: Unexpected end of file while parsing multine var (in c:/work/ConsoleApplication1/bin/Debug/targetDir/config:23, column 0)
at LibGit2Sharp.Core.Ensure.Success(Int32 result, Boolean allowPositiveResult) in c:worklibgit2sharpLibGit2SharpCoreEnsure.cs:line 85
at LibGit2Sharp.Core.Proxy.git_clone_bare(String url, String workdir, git_transfer_progress_callback transfer_cb) in c:worklibgit2sharpLibGit2SharpCoreProxy.cs:line 219
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, Boolean bare, Boolean checkout, TransferProgressHandler onTransferProgress, CheckoutProgressHandler onCheckoutProgress) in c:worklibgit2sharpLibGit2SharpRepository.cs:line 431
at Program.Main() in c:workConsoleApplication1Program.cs:line 12
永远不会创建targetDir
。
另一方面,如果我使用 HTTP 传输,则Repository.Clone
方法工作正常:
var sourceUrl = "https://github.com/libgit2/libgit2sharp";
所以我的问题是我是否做错了什么,或者这是不受支持的功能或本机git2.dll
中的错误?
所以我的问题是我是否做错了什么,或者这是不受支持的功能或本机 git2.dll 中的错误?
实际上,两者兼而有之。
- 第一个例外显然是一个错误。这不应该发生,并且会进行故障排除。
- 第二个需要更深入的分析。你会好心地在 LibGit2Sharp 项目中打开一个问题吗?
好消息是,来自BenStraub的拉取请求最近被合并了。这个拉取请求实现了本地提取传输,这应该可以很好地解决问题。
LibGit2Sharp将在接下来的几天内更新为新版本的libgit2二进制文件,该二进制文件应该允许您执行本地克隆/获取。完成后,我会立即更新此答案。
更新
此测试显示如何对本地存储库执行克隆和推送。