Skip to content

Commit 03b29d1

Browse files
committed
Add null checks to Reference
1 parent c0e139a commit 03b29d1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GitVersion.Extensions;
12
using GitVersion.Helpers;
23
using LibGit2Sharp;
34

@@ -7,25 +8,26 @@ internal sealed class Reference : IReference
78
{
89
private static readonly LambdaEqualityHelper<IReference> equalityHelper = new(x => x.Name.Canonical);
910
private static readonly LambdaKeyComparer<IReference, string> comparerHelper = new(x => x.Name.Canonical);
10-
1111
internal readonly LibGit2Sharp.Reference innerReference;
1212

1313
internal Reference(LibGit2Sharp.Reference reference)
1414
{
15-
this.innerReference = reference;
15+
this.innerReference = reference.NotNull();
1616
Name = new ReferenceName(reference.CanonicalName);
1717

1818
if (reference is DirectReference)
1919
ReferenceTargetId = new ObjectId(reference.TargetIdentifier);
2020
}
21+
2122
public ReferenceName Name { get; }
2223
public IObjectId? ReferenceTargetId { get; }
2324
public int CompareTo(IReference other) => comparerHelper.Compare(this, other);
24-
public override bool Equals(object obj) => Equals((obj as IReference));
25+
public override bool Equals(object obj) => Equals(obj as IReference);
2526
public bool Equals(IReference? other) => equalityHelper.Equals(this, other);
2627
public override int GetHashCode() => equalityHelper.GetHashCode(this);
2728
public override string ToString() => Name.ToString();
2829
public string TargetIdentifier => this.innerReference.TargetIdentifier;
29-
public static implicit operator LibGit2Sharp.Reference(Reference d) => d.innerReference;
30+
public static implicit operator LibGit2Sharp.Reference(Reference d)
31+
=> d.NotNull().innerReference;
3032
}
3133
}

0 commit comments

Comments
 (0)