簡體   English   中英

libgit2sharp刪除遠程分支

[英]libgit2sharp remove remote branch

我想刪除本地和遠程的分支。 我的代碼:

using (var repository = new Repository(path))
{
    var remote = repository.Network.Remotes["origin"];
    var options = new PushOptions();
    var credentials = options.CredentialsProvider = GetUserCredentialsProvider();
    options.CredentialsProvider = credentials;
    string pushRefSpec = @"refs/heads/:{0}".FormatWith(branch);
    repository.Network.Push(remote, pushRefSpec);
    repository.Branches.Remove(repository.Branches[branch]);
}

但我得到401錯誤(“未經授權”)。 這是因為分支名稱中存在“:”。

但是我讀到它們是必要的,因為它們就像本機git中的“--delete”。

謝謝你的幫助!

由於未經授權,因此未通過401 Unauthorized錯誤而失敗。 要修復此錯誤,您只需將包含憑據的options傳遞給Push()方法:

repository.Network.Push(remote, pushRefSpec, options)

這為我解決了這個問題。

我剛剛從libgit2源代碼中找到了解決方案。

repository.Network.Push(origin, "+:/refs/heads/to-remove-branch")

+:/refs/heads/to-remove-branch的part +:/refs/heads/to-remove-branch指定強制刪除命令,否則只需使用:/refs/heads/to-remove-branch

資料來源: https//github.com/libgit2/libgit2/blob/master/tests/online/push.c

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM