[英]Mirror a repo using libgit2sharp (or other c# library)
我想克隆一個 repo,並且我希望克隆擁有原始的所有標簽。 我可以像這樣手動執行此操作
$ git clone --mirror https://github.com/{org}/{SourceProjectName}.git
$ cd {SourceProjectName}.git
$ git push --mirror https://github.com/{org}/{ProjectName}
似乎 libgit2sharp 是最好的方法,但如果有更好的方法請告訴我。
我不明白如何用 libgit2sharp 做它似乎我必須做一個克隆,然后以某種方式復制 refs 然后我必須迭代所有這些 refs 並將它們全部上演......然后提交? 我開始努力做這一切,但感覺就像我在重新發明輪子......
到目前為止我看過的地方:
我不知道這是否是理想的解決方案,但這似乎可以解決問題:
private void DuplicateGitHubRepo()
{
var clonePath = Path.Combine(Path.GetTempPath(), "Temp-" + Guid.NewGuid() + ".git");
var co = new CloneOptions
{
CredentialsProvider = GetGitCredentials()
};
Repository.Clone(SourceProjectUrl+".git", clonePath, co);
using (var repo = new Repository(clonePath))
{
repo.Network.Remotes.Update("origin", x => x.Url = TargetProjectUrl);
var options = new PushOptions
{
CredentialsProvider = GetGitCredentials()
};
repo.Network.Push(repo.Network.Remotes["origin"],repo.Refs.Select(x=>x.CanonicalName),options);
}
}
您鏈接的問題有解決方案。
git mirror clone 只是一個遠程源設置為+refs/*:refs/*
的克隆
using (var repo = new Repository(Repository.Init(@"path\to\local.git", true)))
{
var remote = repo.Network.Remotes.Add("origin", "https://github.com/{org}/{SourceProjectName}.git", "+refs/*:refs/*");
repo.Network.Fetch(remote /* anything for report progress */);
}
RemoteCollection.Add() 方法如下所示: public virtual Remote Add(string name, string url, string fetchRefSpec)
基本上,第三個參數是您需要設置該特殊 refspec 的地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.