Skip to content

Commit c803339

Browse files
committed
Make Branches.Remove() accept a Branch as its target
1 parent 21fea32 commit c803339

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,27 @@ private void AssertRemoval(string branchName, bool isRemote, bool shouldPrevious
454454
[Theory]
455455
[InlineData("i-do-numbers", false)]
456456
[InlineData("origin/br2", true)]
457-
public void CanRemoveAnExistingBranch(string branchName, bool isRemote)
457+
public void CanRemoveAnExistingNamedBranch(string branchName, bool isRemote)
458458
{
459459
AssertRemoval(branchName, isRemote, true);
460460
}
461461

462+
[Theory]
463+
[InlineData("i-do-numbers")]
464+
[InlineData("origin/br2")]
465+
public void CanRemoveAnExistingBranch(string branchName)
466+
{
467+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
468+
469+
using (var repo = new Repository(path.RepositoryPath))
470+
{
471+
Branch curBranch = repo.Branches[branchName];
472+
473+
repo.Branches.Remove(curBranch);
474+
Branch branch = repo.Branches[branchName];
475+
Assert.Null(branch);
476+
}
477+
}
462478

463479
[Theory]
464480
[InlineData("I-donot-exist", false)]

LibGit2Sharp/BranchCollection.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@ public virtual void Remove(string name, bool isRemote = false)
192192
Proxy.git_branch_delete(repo.Handle, name, isRemote ? GitBranchType.GIT_BRANCH_REMOTE : GitBranchType.GIT_BRANCH_LOCAL);
193193
}
194194

195+
/// <summary>
196+
/// Deletes the specified branch.
197+
/// </summary>
198+
/// <param name = "branch">The branch to delete.</param>
199+
public virtual void Remove(Branch branch)
200+
{
201+
Ensure.ArgumentNotNull(branch, "branch");
202+
203+
Remove(branch.Name, branch.IsRemote);
204+
}
205+
195206
/// <summary>
196207
/// Deletes the branch with the specified name.
197208
/// </summary>

0 commit comments

Comments
 (0)