Skip to content

Commit 21f57e8

Browse files
committed
TagCollection proxy
1 parent bca7d95 commit 21f57e8

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/GitVersionCore.Tests/Mocks/MockRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using LibGit2Sharp;
44
using BranchCollection = GitVersion.BranchCollection;
55
using ReferenceCollection = GitVersion.ReferenceCollection;
6+
using TagCollection = GitVersion.TagCollection;
67

78
namespace GitVersionCore.Tests.Mocks
89
{

src/GitVersionCore.Tests/Mocks/MockTagCollection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using LibGit2Sharp;
3+
using TagCollection = GitVersion.TagCollection;
34

45
namespace GitVersionCore.Tests.Mocks
56
{

src/GitVersionCore/Core/GitModel.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ public void Update(Branch branch, params Action<BranchUpdater>[] actions)
3535
}
3636
}
3737

38+
public class TagCollection : IEnumerable<Tag>
39+
{
40+
private readonly LibGit2Sharp.TagCollection innerTagCollection;
41+
private TagCollection(LibGit2Sharp.TagCollection branchCollection) => innerTagCollection = branchCollection;
42+
43+
protected TagCollection()
44+
{
45+
}
46+
47+
public static implicit operator LibGit2Sharp.TagCollection(TagCollection d) => d.innerTagCollection;
48+
public static explicit operator TagCollection(LibGit2Sharp.TagCollection b) => new TagCollection(b);
49+
50+
public virtual IEnumerator<Tag> GetEnumerator()
51+
{
52+
foreach (var branch in innerTagCollection)
53+
yield return branch;
54+
}
55+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
56+
public virtual Tag this[string name] => innerTagCollection[name];
57+
}
58+
3859
public class ReferenceCollection : IEnumerable<Reference>
3960
{
4061
private readonly LibGit2Sharp.ReferenceCollection innerReferenceCollection;

src/GitVersionCore/Core/GitRepository.cs

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

4343
public BranchCollection Branches => (BranchCollection)repositoryInstance.Branches;
4444

45-
public TagCollection Tags => repositoryInstance.Tags;
45+
public TagCollection Tags => (TagCollection)repositoryInstance.Tags;
4646

4747
public RepositoryInformation Info => repositoryInstance.Info;
4848

0 commit comments

Comments
 (0)