如何使用libgit2sharp拉所有新标签

How to pull all new tags using libgit2sharp
2020-11-25
  •  译文(汉语)
  •  原文(英语)

我想使用libgit2sharp实现git pull --tags.如果我尝试做这样的拉动:

repo.Network.Pull(new Signature("name", "my@email.com", new DateTimeOffset()), new PullOptions());

然后我得到新的提交,但没有指向这些提交的新标签.我试图用来PullOptions修改这样的行为:

var sig = new Signature("name", "my@email.com", new DateTimeOffset());
var opts = new PullOptions{ FetchOptions = new FetchOptions {TagFetchMode = TagFetchMode.All} };
repo.Network.Pull(sig, opts);

这将引发以下异常:

LibGit2Sharp.LibGit2SharpException: ref 'refs/remotes/origin/master' doesn't match the destination
  at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
  at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
  at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteSafeHandle remote, Signature signature, String logMessage)
  at LibGit2Sharp.Network.DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, Signature signature, String logMessage)
  at LibGit2Sharp.Network.Fetch(Remote remote, FetchOptions options, Signature signature, String logMessage)
  at LibGit2Sharp.Network.Pull(Signature merger, PullOptions options)

有任何想法吗?

速聊1:
除了下面的答案,抛出的异常不是很明显.您是否介意在跟踪器中针对可公开访问的存储库提供完整的repro案例来解决问题?
解决过程1

坦率地说,我--tags在最新的官方git文档中找不到任何选项.

但是,在LibGit2Sharp中,您可以git fetch --all使用以下代码(或其他.Fetch()重载之一)执行等效操作:

repo.Network.Fetch(remote, new FetchOptions { TagFetchMode = TagFetchMode.All });

更新资料

LibGit2SharpvNext分支的当前提示不喜欢此代码.但是,正如您所提出的问题所示,确实会抛出v0.20.x版本.

v0.21将解决此问题.

速聊1:
git-pull将把任何额外的参数传递给git-fetch.

I would like to use libgit2sharp to achieve git pull --tags. If I try to do a pull like this:

repo.Network.Pull(new Signature("name", "my@email.com", new DateTimeOffset()), new PullOptions());

then I get the new commits but not the new tags which are pointing to these commits. I tried to use PullOptions to modify the behaviour like this:

var sig = new Signature("name", "my@email.com", new DateTimeOffset());
var opts = new PullOptions{ FetchOptions = new FetchOptions {TagFetchMode = TagFetchMode.All} };
repo.Network.Pull(sig, opts);

This throws the following exception:

LibGit2Sharp.LibGit2SharpException: ref 'refs/remotes/origin/master' doesn't match the destination
  at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
  at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
  at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteSafeHandle remote, Signature signature, String logMessage)
  at LibGit2Sharp.Network.DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, Signature signature, String logMessage)
  at LibGit2Sharp.Network.Fetch(Remote remote, FetchOptions options, Signature signature, String logMessage)
  at LibGit2Sharp.Network.Pull(Signature merger, PullOptions options)

Any ideas?

Talk1:
Aside from the answer below, the exception that is thrown isn't very explicit. Would you mind opening an issue in the tracker with a complete repro case against a publicly accessible repository?
Solutions1

Stangely, I can't find any --tags option in the latest official git documentation.

However, in LibGit2Sharp you can perform the equivalent git fetch --all using the following code (or one of the other .Fetch() overloads):

repo.Network.Fetch(remote, new FetchOptions { TagFetchMode = TagFetchMode.All });

Update

The current tip of LibGit2Sharp vNext branch doesn't cringe with this code. However, as seen in the issue you've raised, version v0.20.x does indeed throws.

v0.21 will fix this issue.

Talk1:
git-pull will pass any extra arguments to git-fetch.
转载于:https://stackoverflow.com/questions/28091482/how-to-pull-all-new-tags-using-libgit2sharp

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入