gpt4 book ai didi

c# - NGit 中查看远程仓库是否更改的方法是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:51 24 4
gpt4 key购买 nike

我正在尝试使用 NGit 中的 IsClean()确定是否在工作副本中检测到任何更改,它工作正常,但是当我尝试查看远程中是否有任何更改时,我认为 IsClean() 不是正确的尝试方法。所以我想知道是否有任何其他方法可以帮助我查看远程所做的更改。我尝试 pull 远程仓库,但它似乎确实有效,有谁知道 NGit 中是否有任何方法可以做到这一点。

       var repository = Git.Open(activeRepopath);
var status = repository.Status().Call();
Consoel.WriteLine(stauts.IsClean());

while (status.IsClean())
{
repository.Pull().Call();

}

我从 here 找到了教程在 IsClean() 上。

我实际上想要类似于 buildbot 的 gitpoller 的东西.如果有人能告诉我如何开始,我很乐意朝那个方向努力。

最佳答案

在您给自己的解决方案中,您正在获取 Remote 。这会更改您的本地存储库远程引用,并且可能是也可能不是您想要的。在这个答案中:How to know local repo is different from remote repo, without fetch?它概述了如何使用 ls-remote 命令或 LsRemote 检查 Remote 是否已更改。在这种情况下使用 NGit。

不抓取的检查看起来像这样:

var repository = Git.Open(activeRepopath);
ICollection<Ref> refs = repository.LsRemote().SetHeads(true).SetTags(true).Call();

// Compare the results of GetObjectId() of refs with 'oldRefs', obtained
// previously, to find out if tags or heads changed between the two calls.
// Possibly:
var newIds = refs.Select(r => r.GetObjectId().ToString()).OrderBy(r => r);
var oldIds = oldRefs.Select(r => r.GetObjectId().ToString()).OrderBy(r => r);
if (!newIds.SequenceEqual(oldIds)) {
Console.WriteLine("Something changed");
}

关于c# - NGit 中查看远程仓库是否更改的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22839031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com