Skip to content

Commit 7829cc8

Browse files
committed
Branch proxy
1 parent 21f57e8 commit 7829cc8

File tree

12 files changed

+48
-18
lines changed

12 files changed

+48
-18
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 Branch = GitVersion.Branch;
1112
using BranchCollection = GitVersion.BranchCollection;
1213
using ReferenceCollection = GitVersion.ReferenceCollection;
1314

src/GitVersionCore.Tests/Extensions/GitToolsTestingExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Microsoft.Extensions.DependencyInjection;
1515
using Microsoft.Extensions.Options;
1616
using Shouldly;
17+
using Branch = GitVersion.Branch;
1718

1819
namespace GitVersionCore.Tests
1920
{

src/GitVersionCore.Tests/Mocks/MockBranch.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using LibGit2Sharp;
5+
using Branch = GitVersion.Branch;
56

67
namespace GitVersionCore.Tests.Mocks
78
{
@@ -29,6 +30,7 @@ public MockBranch()
2930
public override ICommitLog Commits => commits;
3031
public override Commit Tip => commits.First();
3132
public override bool IsTracking => true;
33+
public override bool IsRemote => false;
3234

3335
public override string CanonicalName { get; }
3436

src/GitVersionCore.Tests/Mocks/MockBranchCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using LibGit2Sharp;
3+
using Branch = GitVersion.Branch;
44
using BranchCollection = GitVersion.BranchCollection;
55

66
namespace GitVersionCore.Tests.Mocks

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 Branch = GitVersion.Branch;
45
using BranchCollection = GitVersion.BranchCollection;
56
using ReferenceCollection = GitVersion.ReferenceCollection;
67
using TagCollection = GitVersion.TagCollection;

src/GitVersionCore/Core/GitModel.cs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55

66
namespace GitVersion
77
{
8+
public class Branch
9+
{
10+
private readonly LibGit2Sharp.Branch innerBranch;
11+
12+
private Branch(LibGit2Sharp.Branch branch)
13+
{
14+
innerBranch = branch;
15+
}
16+
17+
protected Branch()
18+
{
19+
}
20+
21+
public static implicit operator LibGit2Sharp.Branch(Branch d) => d.innerBranch;
22+
public static explicit operator Branch(LibGit2Sharp.Branch b) => b is null ? null : new Branch(b);
23+
24+
public virtual string CanonicalName => innerBranch.CanonicalName;
25+
public virtual string FriendlyName => innerBranch.FriendlyName;
26+
public virtual Commit Tip => innerBranch.Tip;
27+
public virtual bool IsRemote => innerBranch.IsRemote;
28+
public virtual ICommitLog Commits => innerBranch.Commits;
29+
public virtual bool IsTracking => innerBranch.IsTracking;
30+
}
31+
832
public class BranchCollection : IEnumerable<Branch>
933
{
1034
private readonly LibGit2Sharp.BranchCollection innerBranchCollection;
@@ -15,20 +39,22 @@ protected BranchCollection()
1539
}
1640

1741
public static implicit operator LibGit2Sharp.BranchCollection(BranchCollection d) => d.innerBranchCollection;
18-
public static explicit operator BranchCollection(LibGit2Sharp.BranchCollection b) => new BranchCollection(b);
42+
public static explicit operator BranchCollection(LibGit2Sharp.BranchCollection b) => b is null ? null : new BranchCollection(b);
1943

2044
public virtual IEnumerator<Branch> GetEnumerator()
2145
{
2246
foreach (var branch in innerBranchCollection)
23-
yield return branch;
47+
yield return (Branch)branch;
2448
}
2549

2650
public virtual Branch Add(string name, Commit commit)
2751
{
28-
return innerBranchCollection.Add(name, commit);
52+
return (Branch)innerBranchCollection.Add(name, commit);
2953
}
54+
3055
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
31-
public virtual Branch this[string friendlyName] => innerBranchCollection[friendlyName];
56+
public virtual Branch this[string friendlyName] => (Branch)innerBranchCollection[friendlyName];
57+
3258
public void Update(Branch branch, params Action<BranchUpdater>[] actions)
3359
{
3460
innerBranchCollection.Update(branch, actions);
@@ -45,13 +71,14 @@ protected TagCollection()
4571
}
4672

4773
public static implicit operator LibGit2Sharp.TagCollection(TagCollection d) => d.innerTagCollection;
48-
public static explicit operator TagCollection(LibGit2Sharp.TagCollection b) => new TagCollection(b);
74+
public static explicit operator TagCollection(LibGit2Sharp.TagCollection b) => b is null ? null : new TagCollection(b);
4975

5076
public virtual IEnumerator<Tag> GetEnumerator()
5177
{
5278
foreach (var branch in innerTagCollection)
5379
yield return branch;
5480
}
81+
5582
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
5683
public virtual Tag this[string name] => innerTagCollection[name];
5784
}
@@ -66,7 +93,7 @@ protected ReferenceCollection()
6693
}
6794

6895
public static implicit operator LibGit2Sharp.ReferenceCollection(ReferenceCollection d) => d.innerReferenceCollection;
69-
public static explicit operator ReferenceCollection(LibGit2Sharp.ReferenceCollection b) => new ReferenceCollection(b);
96+
public static explicit operator ReferenceCollection(LibGit2Sharp.ReferenceCollection b) => b is null ? null : new ReferenceCollection(b);
7097

7198
public IEnumerator<Reference> GetEnumerator()
7299
{
@@ -98,6 +125,7 @@ public virtual ReflogCollection Log(string canonicalName)
98125
{
99126
return innerReferenceCollection.Log(canonicalName);
100127
}
128+
101129
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
102130
public virtual Reference this[string name] => innerReferenceCollection[name];
103131
public virtual Reference Head => this["HEAD"];

src/GitVersionCore/Core/GitRepository.cs

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

3535
public RepositoryStatus RetrieveStatus() => repositoryInstance.RetrieveStatus();
3636

37-
public Branch Head => repositoryInstance.Head;
37+
public Branch Head => (Branch)repositoryInstance.Head;
3838

3939
public ReferenceCollection Refs => (ReferenceCollection)repositoryInstance.Refs;
4040

src/GitVersionCore/Core/GitVersionContextFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using GitVersion.Common;
33
using GitVersion.Configuration;
44
using GitVersion.Extensions;
5-
using LibGit2Sharp;
65
using Microsoft.Extensions.Options;
76

87
namespace GitVersion

src/GitVersionCore/Core/RepositoryMetadataProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public bool GetMatchingCommitBranch(Commit baseVersionSource, Branch branch, Com
422422
{
423423
var filter = new CommitFilter
424424
{
425-
IncludeReachableFrom = branch,
425+
IncludeReachableFrom = (LibGit2Sharp.Branch)branch,
426426
ExcludeReachableFrom = baseVersionSource,
427427
FirstParentOnly = true,
428428
};
@@ -457,7 +457,7 @@ private IEnumerable<Commit> GetCommitsReacheableFrom(Commit commit, Branch branc
457457
{
458458
var commits = repository.Commits.QueryBy(new CommitFilter
459459
{
460-
IncludeReachableFrom = branch
460+
IncludeReachableFrom = (LibGit2Sharp.Branch)branch
461461
}).Where(c => c.Sha == commit.Sha);
462462
return commits;
463463
}

src/GitVersionCore/GitVersionCore.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="System.Net.Requests" Version="4.3.0"/>
16+
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
1717

1818
<PackageReference Include="LibGit2Sharp" Version="$(PackageVersion_LibGit2Sharp)"/>
1919
<PackageReference Include="JetBrains.Annotations" Version="$(PackageVersion_JetBrainsAnnotations)" PrivateAssets="All"/>
@@ -25,13 +25,13 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28-
<Compile Remove="VersionConverters\*\AddFormats\**\*.*"/>
29-
<Compile Remove="VersionConverters\*\Templates\**\*.*"/>
28+
<Compile Remove="VersionConverters\*\AddFormats\**\*.*" />
29+
<Compile Remove="VersionConverters\*\Templates\**\*.*" />
3030
</ItemGroup>
3131

3232
<ItemGroup>
33-
<EmbeddedResource Include="VersionConverters\*\AddFormats\**\*.*"/>
34-
<EmbeddedResource Include="VersionConverters\*\Templates\**\*.*"/>
33+
<EmbeddedResource Include="VersionConverters\*\AddFormats\**\*.*" />
34+
<EmbeddedResource Include="VersionConverters\*\Templates\**\*.*" />
3535
</ItemGroup>
3636

3737
</Project>

0 commit comments

Comments
 (0)