【问题标题】:Delete a branch from Remote从远程删除分支
【发布时间】:2021-11-16 00:59:59
【问题描述】:

这是关于 libgit2sharp Remote Fixture 的 API。

我知道如何使用 Push RefSpec 从远程删除分支。但是,我想知道如何使用 API 来做到这一点。我尝试了以下示例,

Repo.Network.Push(Repo.Network.Remotes["origin"], objectish: null, destinationSpec: branchName);

我提供了正确的branchName(已选中远程)。但是,我明白了,

Unhandled exception: System.ArgumentNullException: Value cannot be null. (Parameter 'objectish')
   at LibGit2Sharp.Core.Ensure.ArgumentNotNull(Object argumentValue, String argumentName) in D:\git_ws\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 24
   at LibGit2Sharp.Network.Push(Remote remote, String objectish, String destinationSpec) in D:\git_ws\libgit2sharp\LibGit2Sharp\Network.cs:line 273

相关:https://github.com/libgit2/libgit2sharp/issues/466

如何正确调用Repo.Network.Push从远程删除分支。

出于好奇,我还尝试了RemoteFixture.cs 中的示例,

var remoteBranchName = "origin/" + branchName;
Repo.Branches.Remove(remoteBranchName, true);

这不会引发任何错误。但是,它什么也没做。远程分支仍然存在。

谢谢。 :)

【问题讨论】:

    标签: libgit2sharp


    【解决方案1】:

    你可以使用只接受 push refspecs 的 Push 方法吗?

    public virtual void Push(
                Remote remote,
                string pushRefSpec,
                PushOptions pushOptions)
    

    删除引用的推送 refspec 在此处的“删除引用”部分中进行了描述:

    https://git-scm.com/book/en/v2/Git-Internals-The-Refspec

    类似于:

    :refs/heads/branch-to-delete
    

    【讨论】:

    • 同意@jamill。只是:branch-to-delete 也应该可以工作。看一眼代码,拒绝objectish: null 真的没必要。十年前我做了一个合理的假设。
    • @jamil 感谢您的回复。但是,请注意我在问题描述中提到我可以使用 Refspec 来做到这一点。我想知道是否可以使用libgit2sharp API 以另一种方式做到这一点。
    • 我提到的Push(...) 方法是LibGit2Sharp API 的一部分——那个版本适合你吗? (如果不是,为什么不呢?)看起来对您最初提到的方法的检查可能过于严格,但修改它需要更改 LibGit2Sharp 库中的代码...
    猜你喜欢
    • 2016-07-08
    • 1970-01-01
    • 2023-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 2018-03-06
    • 1970-01-01
    相关资源
    最近更新 更多