libgit2sharp 无法执行存储库推送 - 无法评估表达式,因为代码已优化
libgit2sharp unable to do a repository push - Unable to evaluate expression because the code is optimized
当使用存储库网络 object 进行调试时,实例的快速观察告诉我所有线程都需要 运行ning,这导致了标题中的消息。不知道为什么会这样,但是在进行推送时我收到了该消息。
这里真正的问题是为什么下面的推送与删除和 re-adding 遥控器不起作用的原因。
代码如下 - 所有参数值均有效。对本地回购的承诺正在发挥作用。唯一有效的签名是在移除和 re-add 遥控器后使用遥控器。在下面的这种情况下,分支是正确的。:
private Repository GetGitRepo()
{
string path = Settings.GetSetting(Constants.GitRepositoryPath);
Repository repo = new Repository(path);
return repo;
}
using (var repo = GetGitRepo())
{
if(commit != null)
{
var options = new PushOptions();
options.CredentialsProvider = new CredentialsHandler(
(_url, _user, _cred) =>
new UsernamePasswordCredentials() { Username = Settings.GetSetting(Constants.GitUsername), Password = Settings.GetSetting(Constants.GitPassword) });
repo.Network.Push(_workingBranch, options);
}
}
其他人 运行 解决过这个问题,或者知道我可能遗漏了什么?
提前致谢!
所以这就是最终起作用的方法。我认为问题中所述的信息掩盖了另一个问题。最终删除并重新添加遥控器最终成功了。代码贴在下面:
using (var repo = GetGitRepo())
{
// clean remote by remove and re-add
var remoteName = Settings.GetSetting(Constants.GitUsername);
repo.Network.Remotes.Remove(remoteName);
Remote remote = repo.Network.Remotes.Add(remoteName, Settings.GetSetting(Constants.GitServer));
// build credentials to repo in PushOptions
var options = new PushOptions();
options.CredentialsProvider = new CredentialsHandler(
(_url, _user, _cred) =>
new UsernamePasswordCredentials() { Username = Settings.GetSetting(Constants.GitUsername), Password = Settings.GetSetting(Constants.GitPassword) });
var pushRefSpec = _workingBranch.CanonicalName;
repo.Network.Push(remote, pushRefSpec, options);
}
当使用存储库网络 object 进行调试时,实例的快速观察告诉我所有线程都需要 运行ning,这导致了标题中的消息。不知道为什么会这样,但是在进行推送时我收到了该消息。
这里真正的问题是为什么下面的推送与删除和 re-adding 遥控器不起作用的原因。
代码如下 - 所有参数值均有效。对本地回购的承诺正在发挥作用。唯一有效的签名是在移除和 re-add 遥控器后使用遥控器。在下面的这种情况下,分支是正确的。:
private Repository GetGitRepo()
{
string path = Settings.GetSetting(Constants.GitRepositoryPath);
Repository repo = new Repository(path);
return repo;
}
using (var repo = GetGitRepo())
{
if(commit != null)
{
var options = new PushOptions();
options.CredentialsProvider = new CredentialsHandler(
(_url, _user, _cred) =>
new UsernamePasswordCredentials() { Username = Settings.GetSetting(Constants.GitUsername), Password = Settings.GetSetting(Constants.GitPassword) });
repo.Network.Push(_workingBranch, options);
}
}
其他人 运行 解决过这个问题,或者知道我可能遗漏了什么?
提前致谢!
所以这就是最终起作用的方法。我认为问题中所述的信息掩盖了另一个问题。最终删除并重新添加遥控器最终成功了。代码贴在下面:
using (var repo = GetGitRepo())
{
// clean remote by remove and re-add
var remoteName = Settings.GetSetting(Constants.GitUsername);
repo.Network.Remotes.Remove(remoteName);
Remote remote = repo.Network.Remotes.Add(remoteName, Settings.GetSetting(Constants.GitServer));
// build credentials to repo in PushOptions
var options = new PushOptions();
options.CredentialsProvider = new CredentialsHandler(
(_url, _user, _cred) =>
new UsernamePasswordCredentials() { Username = Settings.GetSetting(Constants.GitUsername), Password = Settings.GetSetting(Constants.GitPassword) });
var pushRefSpec = _workingBranch.CanonicalName;
repo.Network.Push(remote, pushRefSpec, options);
}