在 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
Push 操作期间提供包构建、传输和错误状态,但理想情况下,我想捕获远程响应(如上所列)并将其反馈给客户端。有什么办法可以用 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);
}