2
votes

I am fairly new to Git/LibGit2Sharp and am trying to create a mirror of a git repository using LibGit2Sharp. Following the directions given here: https://github.com/libgit2/libgit2sharp/issues/577, I first mirrored the external repository to a local folder by adding a remote to it, and used repo.Network.fetch(remote, fetchRefSpec) where fetchRefSpec is refs/\*:refs/*

Now, I want to push the data to another remote repository. Here I am confused. Because, when doing this through git commands, you set the remote.remoteName.mirror config entry to true and then do git push remoteName. Specifying any other refSpec when mirror is set to true gives an error.

However, when using LibGit2Sharp, even after I set mirror = true, I still have to provide a pushRefSpec while pushing. Providing empty or wildcard refSpecs throws exception. I even tried refs/tags/\*:refs/tags/*, but I got the same exception. Looping through all branches in the pushRefSpec works, but does not create a mirror.

Has anyone tried this? Is there probably a better way to do this?

1

1 Answers

2
votes

The .mirror configuration is an option for the git tool. libgit2(sharp) works at a different level, where you need to specify exactly what you want to push.

At the moment it unfortunately does not support refspecs with a pattern on push, so if you want to push every reference, you'll have to add each of them individually as refspecs for the push.