使用LibGit2Sharp推送时的远程响应

时间:2014-03-03 14:54:21

标签: libgit2 libgit2sharp

在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.

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

以下是使用LibGit2Sharp版本0.16.0.0的Push动作片段

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);
}

1 个答案:

答案 0 :(得分:3)

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

一旦这样做,它看起来就像Fetch的{​​{1}}。