Skip to content

Commit 26a89e5

Browse files
committed
BranchCollection proxy
1 parent 422d0bf commit 26a89e5

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using LibGit2Sharp;
99
using NSubstitute;
1010
using NUnit.Framework;
11+
using BranchCollection = GitVersion.BranchCollection;
1112

1213
namespace GitVersionCore.Tests
1314
{

src/GitVersionCore.Tests/Mocks/MockBranchCollection.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using LibGit2Sharp;
4+
using BranchCollection = GitVersion.BranchCollection;
45

56
namespace GitVersionCore.Tests.Mocks
67
{
@@ -38,11 +39,6 @@ public void CopyTo(Branch[] array, int arrayIndex)
3839
Branches.CopyTo(array, arrayIndex);
3940
}
4041

41-
public override void Remove(Branch item)
42-
{
43-
Branches.Remove(item);
44-
}
45-
4642
public int Count => Branches.Count;
4743
public bool IsReadOnly => false;
4844
}

src/GitVersionCore.Tests/Mocks/MockRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using GitVersion;
33
using LibGit2Sharp;
4+
using BranchCollection = GitVersion.BranchCollection;
45

56
namespace GitVersionCore.Tests.Mocks
67
{

src/GitVersionCore/Core/GitModel.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using LibGit2Sharp;
5+
6+
namespace GitVersion
7+
{
8+
public class BranchCollection : IEnumerable<Branch>
9+
{
10+
private readonly LibGit2Sharp.BranchCollection innerBranchCollection;
11+
private BranchCollection(LibGit2Sharp.BranchCollection branchCollection) => innerBranchCollection = branchCollection;
12+
13+
protected BranchCollection()
14+
{
15+
}
16+
17+
public static implicit operator LibGit2Sharp.BranchCollection(BranchCollection d) => d.innerBranchCollection;
18+
public static explicit operator BranchCollection(LibGit2Sharp.BranchCollection b) => new BranchCollection(b);
19+
20+
public virtual IEnumerator<Branch> GetEnumerator()
21+
{
22+
foreach (var branch in innerBranchCollection)
23+
yield return branch;
24+
}
25+
26+
public virtual Branch Add(string name, Commit commit)
27+
{
28+
return innerBranchCollection.Add(name, commit);
29+
}
30+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
31+
public virtual Branch this[string friendlyName] => innerBranchCollection[friendlyName];
32+
public void Update(Branch branch, params Action<BranchUpdater>[] actions)
33+
{
34+
innerBranchCollection.Update(branch, actions);
35+
}
36+
}
37+
}

src/GitVersionCore/Core/GitRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void Dispose()
4040

4141
public IQueryableCommitLog Commits => repositoryInstance.Commits;
4242

43-
public BranchCollection Branches => repositoryInstance.Branches;
43+
public BranchCollection Branches => (BranchCollection)repositoryInstance.Branches;
4444

4545
public TagCollection Tags => repositoryInstance.Tags;
4646

0 commit comments

Comments
 (0)