1

在 LibGit2Sharp 中是否有在进行推送时获得远程响应?

当使用 git bash 命令行之类的东西时,您会在控制台中获得以下输出:

remote: Updating branch 'master'.
remote: Updating submodules.
remote: Preparing deployment for commit id '3fe0a458ac'.
remote: Generating deployment script.
remote: Running deployment command...
remote: Handling Basic Web Site deployment.

PushOptionsPush 操作期间提供包构建、传输和错误状态,但理想情况下,我想捕获远程响应(如上所列)并将其反馈给客户端。有什么办法可以用 libgit2 / LibGit2Sharp 做到这一点?

这是我使用 LibGit2Sharp 版本 0.16.0.0 的推送操作的片段

using (var repository = new Repository(sourceRepositoryPath))
{
    var pushOptions = new PushOptions
    {
        Credentials = new Credentials { Username = remoteUser, Password = remotePassword },
        OnPackBuilderProgress = (stage, current, total) =>
        {
            Trace.WriteLine(string.Format("Pack Building Progress {0} out of {1}, Stage {2}",
                current, total, stage));
            return true;
        },
        OnPushStatusError = errors =>
        {
            Trace.WriteLine(errors);
        },
        OnPushTransferProgress = (current, total, bytes) =>
        {
            Trace.WriteLine(string.Format("Transfer Progress {0} out of {1}, Bytes {2}", current, total, bytes));
            return true;
        }
    };
    string pushRefSpec = string.Format("+{0}:{0}", "refs/heads/master");
    var remote = repository.Network.Remotes["origin"];
    repository.Network.Push(remote, pushRefSpec, pushOptions);
}
4

1 回答 1

3

该信息由服务器进程在称为“进度”的特定通道中发送,这需要双方之间达成支持此扩展的协议。libgit2 本身已经学会了如何做到这一点,但 libgit2sharp 尚未更新以支持这个额外的通道。

一旦这样做,它看起来像Fetch's OnProgress

于 2014-03-03T16:53:02.667 回答