Skip to content

Commit 089032a

Browse files
committed
made inner*Property* non nullable
1 parent 01aaeb7 commit 089032a

17 files changed

+106
-169
lines changed

src/GitVersion.LibGit2Sharp/Git/Branch.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ protected Branch()
2525
public override bool Equals(object obj) => Equals(obj as IBranch);
2626
public bool Equals(IBranch other) => equalityHelper.Equals(this, other);
2727
public override int GetHashCode() => equalityHelper.GetHashCode(this);
28-
public static implicit operator LibGit2Sharp.Branch(Branch d) => d?.innerBranch;
28+
public static implicit operator LibGit2Sharp.Branch(Branch d) => d.innerBranch;
2929

30-
public virtual string CanonicalName => innerBranch?.CanonicalName;
31-
public virtual string FriendlyName => innerBranch?.FriendlyName;
30+
public virtual string CanonicalName => innerBranch.CanonicalName;
31+
public virtual string FriendlyName => innerBranch.FriendlyName;
3232

3333
public string NameWithoutRemote =>
3434
IsRemote
@@ -44,7 +44,7 @@ public virtual ICommit Tip
4444
{
4545
get
4646
{
47-
var commit = innerBranch?.Tip;
47+
var commit = innerBranch.Tip;
4848
return commit is null ? null : new Commit(commit);
4949
}
5050
}
@@ -54,7 +54,7 @@ public virtual ICommitCollection Commits
5454
get
5555
{
5656

57-
var commits = innerBranch?.Commits;
57+
var commits = innerBranch.Commits;
5858
return commits is null ? null : new CommitCollection(commits);
5959
}
6060
}
@@ -70,7 +70,7 @@ public bool IsSameBranch(IBranch otherBranch)
7070
}
7171
public bool IsDetachedHead => CanonicalName.Equals("(no branch)", StringComparison.OrdinalIgnoreCase);
7272

73-
public virtual bool IsRemote => innerBranch != null && innerBranch.IsRemote;
74-
public virtual bool IsTracking => innerBranch != null && innerBranch.IsTracking;
73+
public virtual bool IsRemote => innerBranch.IsRemote;
74+
public virtual bool IsTracking => innerBranch.IsTracking;
7575
}
7676
}

src/GitVersion.LibGit2Sharp/Git/Commit.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected Commit()
2727
public bool Equals(ICommit other) => equalityHelper.Equals(this, other);
2828
public override int GetHashCode() => equalityHelper.GetHashCode(this);
2929

30-
public static implicit operator LibGit2Sharp.Commit(Commit d) => d?.innerObjectId;
30+
public static implicit operator LibGit2Sharp.Commit(Commit d) => d.innerObjectId;
3131

3232
public virtual IEnumerable<ICommit> Parents
3333
{
@@ -40,18 +40,18 @@ public virtual IEnumerable<ICommit> Parents
4040
}
4141
}
4242

43-
public virtual string Sha => innerObjectId?.Sha;
43+
public virtual string Sha => innerObjectId.Sha;
4444

4545
public virtual IObjectId Id
4646
{
4747
get
4848
{
49-
var objectId = innerObjectId?.Id;
49+
var objectId = innerObjectId.Id;
5050
return objectId is null ? null : new ObjectId(objectId);
5151
}
5252
}
5353

54-
public virtual DateTimeOffset? CommitterWhen => innerObjectId?.Committer.When;
55-
public virtual string Message => innerObjectId?.Message;
54+
public virtual DateTimeOffset? CommitterWhen => innerObjectId.Committer.When;
55+
public virtual string Message => innerObjectId.Message;
5656
}
5757
}

src/GitVersion.LibGit2Sharp/Git/ObjectId.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public ObjectId(string sha) : this(new LibGit2Sharp.ObjectId(sha))
2323
public override bool Equals(object obj) => Equals(obj as IObjectId);
2424
public bool Equals(IObjectId other) => equalityHelper.Equals(this, other);
2525
public override int GetHashCode() => equalityHelper.GetHashCode(this);
26-
public static implicit operator LibGit2Sharp.ObjectId(ObjectId d) => d?.innerObjectId;
27-
public string Sha => innerObjectId?.Sha;
26+
public static implicit operator LibGit2Sharp.ObjectId(ObjectId d) => d.innerObjectId;
27+
public string Sha => innerObjectId.Sha;
2828

2929
public string ToString(int prefixLength) => innerObjectId.ToString(prefixLength);
3030
}

src/GitVersion.LibGit2Sharp/Git/Reference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ protected Reference()
3232
public virtual string DirectReferenceTargetIdentifier => directReference.TargetIdentifier;
3333
public virtual IObjectId DirectReferenceTargetId => new ObjectId(directReference.Target.Id);
3434
public virtual IReference ResolveToDirectReference() => new Reference(directReference);
35-
public static implicit operator LibGit2Sharp.Reference(Reference d) => d?.innerReference;
35+
public static implicit operator LibGit2Sharp.Reference(Reference d) => d.innerReference;
3636
}
3737
}

src/GitVersion.LibGit2Sharp/Git/Tag.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ protected Tag()
2424
public override bool Equals(object obj) => Equals(obj as ITag);
2525
public bool Equals(ITag other) => equalityHelper.Equals(this, other);
2626
public override int GetHashCode() => equalityHelper.GetHashCode(this);
27-
public virtual string CanonicalName => innerTag?.CanonicalName;
28-
public virtual string TargetSha => innerTag?.Target.Sha;
29-
public virtual string FriendlyName => innerTag?.FriendlyName;
27+
public virtual string CanonicalName => innerTag.CanonicalName;
28+
public virtual string TargetSha => innerTag.Target.Sha;
29+
public virtual string FriendlyName => innerTag.FriendlyName;
3030

3131
public ICommit PeeledTargetCommit()
3232
{

src/GitVersionCore.Tests/Core/RepositoryExtensionsTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public TestableCommit(IObjectId id)
147147
}
148148

149149
public override IObjectId Id => id;
150+
public override string Sha => id.Sha;
150151
}
151152

152153
private class TesatbleRemote : Remote

src/GitVersionCore.Tests/Helpers/GitVersionContextBuilder.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,6 @@ public GitVersionContextBuilder OverrideServices(Action<IServiceCollection> over
3636
return this;
3737
}
3838

39-
public GitVersionContextBuilder WithTaggedMaster()
40-
{
41-
repository = CreateRepository();
42-
((MockTagCollection)repository.Tags).Add(new MockTag("1.0.0"));
43-
return this;
44-
}
45-
46-
public GitVersionContextBuilder AddCommit()
47-
{
48-
((MockBranch)repository.Head).Add(new MockCommit());
49-
return this;
50-
}
51-
5239
public GitVersionContextBuilder WithDevelopBranch()
5340
{
5441
return WithBranch("develop");
@@ -102,7 +89,6 @@ private static IGitRepository CreateRepository()
10289
{
10390
mockBranch
10491
},
105-
Tags = new MockTagCollection(),
10692
Head = mockBranch
10793
};
10894

src/GitVersionCore.Tests/Mocks/MockBranch.cs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,61 @@
1+
using System;
12
using System.Collections;
23
using System.Collections.Generic;
34
using System.Linq;
45
using GitVersion;
6+
using GitVersion.Extensions;
57

68
namespace GitVersionCore.Tests.Mocks
79
{
8-
internal class MockBranch : Branch, ICollection<ICommit>
10+
internal class MockBranch : IBranch, ICollection<ICommit>
911
{
1012
public MockBranch(string friendlyName)
1113
{
1214
this.friendlyName = friendlyName;
1315
CanonicalName = friendlyName;
1416
}
15-
public MockBranch(string friendlyName, string canonicalName)
16-
{
17-
this.friendlyName = friendlyName;
18-
CanonicalName = canonicalName;
19-
}
2017

21-
public MockBranch()
18+
private readonly MockCommitCollection commits = new MockCommitCollection();
19+
private readonly string friendlyName;
20+
public string FriendlyName => friendlyName;
21+
public string NameWithoutRemote =>
22+
IsRemote
23+
? FriendlyName.Substring(FriendlyName.IndexOf("/", StringComparison.Ordinal) + 1)
24+
: FriendlyName;
25+
26+
public string NameWithoutOrigin =>
27+
IsRemote && FriendlyName.StartsWith("origin/")
28+
? FriendlyName.Substring("origin/".Length)
29+
: FriendlyName;
30+
public bool IsSameBranch(IBranch otherBranch)
2231
{
23-
32+
// For each branch, fixup the friendly name if the branch is remote.
33+
var otherBranchFriendlyName = otherBranch.NameWithoutRemote;
34+
return otherBranchFriendlyName.IsEquivalentTo(NameWithoutRemote);
2435
}
36+
public bool IsDetachedHead => CanonicalName.Equals("(no branch)", StringComparison.OrdinalIgnoreCase);
2537

26-
private readonly MockCommitCollection commits = new MockCommitCollection();
27-
private readonly string friendlyName;
28-
public override string FriendlyName => friendlyName;
29-
public override ICommitCollection Commits => commits;
30-
public override ICommit Tip => commits.First();
31-
public override bool IsTracking => true;
32-
public override bool IsRemote => false;
38+
public ICommitCollection Commits => commits;
39+
public ICommit Tip => commits.First();
40+
public bool IsTracking => true;
41+
public bool IsRemote => false;
42+
public bool IsReadOnly => false;
3343

34-
public override string CanonicalName { get; }
44+
public string CanonicalName { get; }
3545

3646
public override int GetHashCode()
3747
{
3848
return friendlyName.GetHashCode();
3949
}
4050

51+
public bool Equals(IBranch other)
52+
{
53+
throw new NotImplementedException();
54+
}
55+
public int CompareTo(IBranch other)
56+
{
57+
throw new NotImplementedException();
58+
}
4159
public override bool Equals(object obj)
4260
{
4361
return ReferenceEquals(this, obj);
@@ -79,7 +97,5 @@ public bool Remove(ICommit item)
7997
}
8098

8199
public int Count => commits.Count;
82-
83-
public bool IsReadOnly => false;
84100
}
85101
}
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1+
using System.Collections;
12
using System.Collections.Generic;
23
using System.Linq;
34
using GitVersion;
45

56
namespace GitVersionCore.Tests.Mocks
67
{
7-
internal class MockBranchCollection : BranchCollection
8+
internal class MockBranchCollection : IBranchCollection
89
{
910
private List<IBranch> Branches = new List<IBranch>();
1011

11-
public override IEnumerator<IBranch> GetEnumerator()
12+
public IEnumerator<IBranch> GetEnumerator()
1213
{
1314
return Branches.GetEnumerator();
1415
}
1516

16-
public override IBranch this[string friendlyName]
17+
public IBranch this[string friendlyName] => Branches.FirstOrDefault(x => x.FriendlyName == friendlyName);
18+
public IEnumerable<IBranch> ExcludeBranches(IEnumerable<IBranch> branchesToExclude)
1719
{
18-
get { return Branches.FirstOrDefault(x => x.FriendlyName == friendlyName); }
20+
throw new System.NotImplementedException();
21+
}
22+
public void UpdateTrackedBranch(IBranch branch, string remoteTrackingReferenceName)
23+
{
24+
throw new System.NotImplementedException();
1925
}
2026

2127
public void Add(IBranch item)
2228
{
2329
Branches.Add(item);
2430
}
31+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
2532
}
2633
}

src/GitVersionCore.Tests/Mocks/MockCommit.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
using System.Diagnostics;
44
using GitVersion;
55
using LibGit2Sharp;
6-
using Commit = GitVersion.Commit;
7-
using ObjectId = GitVersion.ObjectId;
6+
using NSubstitute;
87

98
namespace GitVersionCore.Tests.Mocks
109
{
1110
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + "}")]
12-
internal class MockCommit : Commit
11+
internal class MockCommit : ICommit
1312
{
1413
private static int commitCount = 1;
1514
private static DateTimeOffset when = DateTimeOffset.Now;
1615

17-
public MockCommit(IObjectId id = null)
16+
public MockCommit()
1817
{
19-
idEx = id ?? new ObjectId(Guid.NewGuid().ToString().Replace("-", "") + "00000000");
18+
idEx = Substitute.For<IObjectId>();
19+
idEx.Sha.Returns(Guid.NewGuid().ToString().Replace("-", "") + "00000000");
2020
MessageEx = "Commit " + commitCount++;
2121
ParentsEx = new List<ICommit> { null };
2222
CommitterEx = new Signature("Joe", "[email protected]", when);
@@ -25,20 +25,28 @@ public MockCommit(IObjectId id = null)
2525
}
2626

2727
public string MessageEx;
28-
public override string Message => MessageEx;
28+
public string Message => MessageEx;
2929

3030
public Signature CommitterEx;
31-
public override DateTimeOffset? CommitterWhen => CommitterEx.When;
31+
public DateTimeOffset? CommitterWhen => CommitterEx.When;
3232

3333
private readonly IObjectId idEx;
34-
public override IObjectId Id => idEx;
34+
public IObjectId Id => idEx;
3535

36-
public override string Sha => idEx.Sha;
36+
public string Sha => idEx.Sha;
3737

3838
public IList<ICommit> ParentsEx;
39-
public override IEnumerable<ICommit> Parents => ParentsEx;
39+
public IEnumerable<ICommit> Parents => ParentsEx;
4040

4141
// ReSharper disable once UnusedMember.Local
4242
private string DebuggerDisplay => MessageEx;
43+
public bool Equals(ICommit other)
44+
{
45+
throw new NotImplementedException();
46+
}
47+
public int CompareTo(ICommit other)
48+
{
49+
throw new NotImplementedException();
50+
}
4351
}
4452
}

0 commit comments

Comments
 (0)