Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,6 @@ dotnet_diagnostic.CA1810.severity = warning

# CA1816: Dispose methods should call SuppressFinalize
dotnet_diagnostic.CA1816.severity = warning

# IDE0005: Using directive is unnecessary.
dotnet_diagnostic.IDE0005.severity = warning
6 changes: 3 additions & 3 deletions src/GitVersion.Core/Configuration/ConfigFileLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public ConfigFileLocator(IFileSystem fileSystem, IOptions<GitVersionOptions> opt

public string FilePath { get; }

public bool HasConfigFileAt(string? workingDirectory) => this.fileSystem.Exists(Path.Combine(workingDirectory, FilePath));
public bool HasConfigFileAt(string workingDirectory) => this.fileSystem.Exists(Path.Combine(workingDirectory, FilePath));

public string GetConfigFilePath(string? workingDirectory) => Path.Combine(workingDirectory, FilePath);
public string GetConfigFilePath(string workingDirectory) => Path.Combine(workingDirectory, FilePath);

public void Verify(string? workingDirectory, string? projectRootDirectory)
{
Expand All @@ -40,7 +40,7 @@ public string SelectConfigFilePath(GitVersionOptions gitVersionOptions, IGitRepo
return GetConfigFilePath(HasConfigFileAt(workingDirectory) ? workingDirectory : projectRootDirectory);
}

public Config ReadConfig(string? workingDirectory)
public Config ReadConfig(string workingDirectory)
{
var configFilePath = GetConfigFilePath(workingDirectory);

Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Configuration/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Config Provide(Config? overrideConfig = null)
return Provide(rootDirectory, overrideConfig);
}

public Config Provide(string? workingDirectory, Config? overrideConfig = null) =>
public Config Provide(string workingDirectory, Config? overrideConfig = null) =>
new ConfigurationBuilder()
.Add(this.configFileLocator.ReadConfig(workingDirectory))
.Add(overrideConfig ?? new Config())
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/IBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion
{
public interface IBranch : IEquatable<IBranch>, IComparable<IBranch>, INamedReference
public interface IBranch : IEquatable<IBranch?>, IComparable<IBranch>, INamedReference
{
ICommit? Tip { get; }
bool IsRemote { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/ICommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace GitVersion
{
public interface ICommit : IEquatable<ICommit>, IComparable<ICommit>, IGitObject
public interface ICommit : IEquatable<ICommit?>, IComparable<ICommit>, IGitObject
{
IEnumerable<ICommit> Parents { get; }
DateTimeOffset When { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/IGitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion
{
public interface IGitObject : IEquatable<IGitObject>, IComparable<IGitObject>
public interface IGitObject : IEquatable<IGitObject?>, IComparable<IGitObject>
{
IObjectId Id { get; }
string Sha { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/IObjectId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion
{
public interface IObjectId : IEquatable<IObjectId>, IComparable<IObjectId>
public interface IObjectId : IEquatable<IObjectId?>, IComparable<IObjectId>
{
string Sha { get; }
string ToString(int prefixLength);
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/IRefSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion
{
public interface IRefSpec : IEquatable<IRefSpec>, IComparable<IRefSpec>
public interface IRefSpec : IEquatable<IRefSpec?>, IComparable<IRefSpec>
{
string Specification { get; }
RefSpecDirection Direction { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/IReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion
{
public interface IReference : IEquatable<IReference>, IComparable<IReference>, INamedReference
public interface IReference : IEquatable<IReference?>, IComparable<IReference>, INamedReference
{
string TargetIdentifier { get; }
IObjectId? ReferenceTargetId { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/IRemote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace GitVersion
{
public interface IRemote : IEquatable<IRemote>, IComparable<IRemote>
public interface IRemote : IEquatable<IRemote?>, IComparable<IRemote>
{
string Name { get; }
string Url { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/ITag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitVersion
{
public interface ITag : IEquatable<ITag>, IComparable<ITag>, INamedReference
public interface ITag : IEquatable<ITag?>, IComparable<ITag>, INamedReference
{
string TargetSha { get; }
ICommit? PeeledTargetCommit();
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersion.Core/Git/ReferenceName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace GitVersion
{
public class ReferenceName : IEquatable<ReferenceName>, IComparable<ReferenceName>
public class ReferenceName : IEquatable<ReferenceName?>, IComparable<ReferenceName>
{
private static readonly LambdaEqualityHelper<ReferenceName> equalityHelper = new(x => x?.Canonical);
private static readonly LambdaEqualityHelper<ReferenceName> equalityHelper = new(x => x.Canonical);
private static readonly LambdaKeyComparer<ReferenceName, string> comparerHelper = new(x => x.Canonical);

private const string LocalBranchPrefix = "refs/heads/";
Expand Down Expand Up @@ -46,7 +46,7 @@ public static ReferenceName Parse(string canonicalName)
public bool IsTag { get; }
public bool IsPullRequest { get; }

public bool Equals(ReferenceName other) => equalityHelper.Equals(this, other);
public bool Equals(ReferenceName? other) => equalityHelper.Equals(this, other);
public int CompareTo(ReferenceName other) => comparerHelper.Compare(this, other);
public override bool Equals(object obj) => Equals((obj as ReferenceName)!);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.Core/Helpers/LambdaEqualityHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace GitVersion.Helpers
// see https://github.com/libgit2/libgit2sharp/blob/7af5c60f22f9bd6064204f84467cfa62bedd1147/LibGit2Sharp/Core/LambdaEqualityHelper.cs
public class LambdaEqualityHelper<T>
{
private readonly Func<T?, object?>[] equalityContributorAccessors;
private readonly Func<T, object?>[] equalityContributorAccessors;

public LambdaEqualityHelper(params Func<T?, object?>[] equalityContributorAccessors) =>
public LambdaEqualityHelper(params Func<T, object?>[] equalityContributorAccessors) =>
this.equalityContributorAccessors = equalityContributorAccessors;

public bool Equals(T? instance, T? other)
Expand Down
11 changes: 3 additions & 8 deletions src/GitVersion.Core/Model/BranchCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace GitVersion
/// <summary>
/// A commit, together with the branch to which the commit belongs.
/// </summary>
public readonly struct BranchCommit
public readonly struct BranchCommit : IEquatable<BranchCommit?>
{
public static readonly BranchCommit Empty = new();

Expand All @@ -18,14 +18,9 @@ public BranchCommit(ICommit commit, IBranch branch) : this()
public IBranch Branch { get; }
public ICommit Commit { get; }

private bool Equals(BranchCommit other) => Equals(Branch, other.Branch) && Equals(Commit, other.Commit);
public bool Equals(BranchCommit? other) => Equals(Branch, other?.Branch) && Equals(Commit, other?.Commit);

public override bool Equals(object obj)
{
if (obj is null)
return false;
return obj is BranchCommit commit && Equals(commit);
}
public override bool Equals(object obj) => obj is null ? false : Equals(obj as BranchCommit?);

public override int GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace GitVersion
{
public class SemanticVersion : IFormattable, IComparable<SemanticVersion>
public class SemanticVersion : IFormattable, IComparable<SemanticVersion>, IEquatable<SemanticVersion?>
{
private static readonly SemanticVersion Empty = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

namespace GitVersion
{
public class SemanticVersionBuildMetaData : IFormattable, IEquatable<SemanticVersionBuildMetaData>
public class SemanticVersionBuildMetaData : IFormattable, IEquatable<SemanticVersionBuildMetaData?>
{
private static readonly Regex ParseRegex = new(
@"(?<BuildNumber>\d+)?(\.?Branch(Name)?\.(?<BranchName>[^\.]+))?(\.?Sha?\.(?<Sha>[^\.]+))?(?<Other>.*)",
RegexOptions.Compiled | RegexOptions.IgnoreCase);

private static readonly LambdaEqualityHelper<SemanticVersionBuildMetaData> EqualityHelper =
new(x => x?.CommitsSinceTag, x => x?.Branch, x => x?.Sha);
new(x => x.CommitsSinceTag, x => x.Branch, x => x.Sha);

public int? CommitsSinceTag;
public string? Branch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
namespace GitVersion
{
public class SemanticVersionPreReleaseTag :
IFormattable, IComparable<SemanticVersionPreReleaseTag>, IEquatable<SemanticVersionPreReleaseTag>
IFormattable, IComparable<SemanticVersionPreReleaseTag>, IEquatable<SemanticVersionPreReleaseTag?>
{
private static readonly LambdaEqualityHelper<SemanticVersionPreReleaseTag> EqualityHelper =
new(x => x?.Name, x => x?.Number);
new(x => x.Name, x => x.Number);

public SemanticVersionPreReleaseTag()
{
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace GitVersion
{
internal sealed class Branch : IBranch
{
private static readonly LambdaEqualityHelper<IBranch> equalityHelper = new(x => x?.Name.Canonical);
private static readonly LambdaEqualityHelper<IBranch> equalityHelper = new(x => x.Name.Canonical);
private static readonly LambdaKeyComparer<IBranch, string> comparerHelper = new(x => x.Name.Canonical);

private readonly LibGit2Sharp.Branch innerBranch;
Expand All @@ -26,7 +26,7 @@ internal Branch(LibGit2Sharp.Branch branch)
public ICommitCollection? Commits { get; }

public int CompareTo(IBranch other) => comparerHelper.Compare(this, other);
public bool Equals(IBranch other) => equalityHelper.Equals(this, other);
public bool Equals(IBranch? other) => equalityHelper.Equals(this, other);
public override bool Equals(object obj) => Equals((obj as IBranch)!);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => Name.ToString();
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GitVersion
{
internal sealed class Commit : GitObject, ICommit
{
private static readonly LambdaEqualityHelper<ICommit> equalityHelper = new(x => x?.Id);
private static readonly LambdaEqualityHelper<ICommit> equalityHelper = new(x => x.Id);
private static readonly LambdaKeyComparer<ICommit, string> comparerHelper = new(x => x.Sha);

private readonly LibGit2Sharp.Commit innerCommit;
Expand All @@ -20,7 +20,7 @@ internal Commit(LibGit2Sharp.Commit innerCommit) : base(innerCommit)
}

public int CompareTo(ICommit other) => comparerHelper.Compare(this, other);
public bool Equals(ICommit other) => equalityHelper.Equals(this, other);
public bool Equals(ICommit? other) => equalityHelper.Equals(this, other);
public override bool Equals(object obj) => Equals((obj as ICommit)!);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => $"{Id.ToString(7)} {this.innerCommit.MessageShort}";
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/GitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GitVersion
{
internal class GitObject : IGitObject
{
private static readonly LambdaEqualityHelper<IGitObject> equalityHelper = new(x => x?.Id);
private static readonly LambdaEqualityHelper<IGitObject> equalityHelper = new(x => x.Id);
private static readonly LambdaKeyComparer<IGitObject, string> comparerHelper = new(x => x.Sha);

internal GitObject(LibGit2Sharp.GitObject innerGitObject)
Expand All @@ -14,7 +14,7 @@ internal GitObject(LibGit2Sharp.GitObject innerGitObject)
}

public int CompareTo(IGitObject other) => comparerHelper.Compare(this, other);
public bool Equals(IGitObject other) => equalityHelper.Equals(this, other);
public bool Equals(IGitObject? other) => equalityHelper.Equals(this, other);
public override bool Equals(object obj) => Equals((obj as IGitObject)!);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => Id.ToString(7);
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/ObjectId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GitVersion
{
internal sealed class ObjectId : IObjectId
{
private static readonly LambdaEqualityHelper<IObjectId> equalityHelper = new(x => x?.Sha);
private static readonly LambdaEqualityHelper<IObjectId> equalityHelper = new(x => x.Sha);
private static readonly LambdaKeyComparer<IObjectId, string> comparerHelper = new(x => x.Sha);

private readonly LibGit2Sharp.ObjectId innerObjectId;
Expand All @@ -15,7 +15,7 @@ public ObjectId(string sha) : this(new LibGit2Sharp.ObjectId(sha))
}

public int CompareTo(IObjectId other) => comparerHelper.Compare(this, other);
public bool Equals(IObjectId other) => equalityHelper.Equals(this, other);
public bool Equals(IObjectId? other) => equalityHelper.Equals(this, other);
public override bool Equals(object obj) => Equals((obj as IObjectId)!);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => ToString(7);
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/RefSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ namespace GitVersion
{
public class RefSpec : IRefSpec
{
private static readonly LambdaEqualityHelper<IRefSpec> equalityHelper = new(x => x?.Specification);
private static readonly LambdaEqualityHelper<IRefSpec> equalityHelper = new(x => x.Specification);
private static readonly LambdaKeyComparer<IRefSpec, string> comparerHelper = new(x => x.Specification);

private readonly LibGit2Sharp.RefSpec innerRefSpec;

internal RefSpec(LibGit2Sharp.RefSpec refSpec) => this.innerRefSpec = refSpec;
public int CompareTo(IRefSpec other) => comparerHelper.Compare(this, other);
public bool Equals(IRefSpec other) => equalityHelper.Equals(this, other);
public bool Equals(IRefSpec? other) => equalityHelper.Equals(this, other);
public override bool Equals(object obj) => Equals((obj as IRefSpec)!);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => Specification;
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace GitVersion
{
internal sealed class Reference : IReference
{
private static readonly LambdaEqualityHelper<IReference> equalityHelper = new(x => x?.Name.Canonical);
private static readonly LambdaEqualityHelper<IReference> equalityHelper = new(x => x.Name.Canonical);
private static readonly LambdaKeyComparer<IReference, string> comparerHelper = new(x => x.Name.Canonical);

internal readonly LibGit2Sharp.Reference innerReference;
Expand All @@ -22,7 +22,7 @@ internal Reference(LibGit2Sharp.Reference reference)
public IObjectId? ReferenceTargetId { get; }
public int CompareTo(IReference other) => comparerHelper.Compare(this, other);
public override bool Equals(object obj) => Equals((obj as IReference)!);
public bool Equals(IReference other) => equalityHelper.Equals(this, other);
public bool Equals(IReference? other) => equalityHelper.Equals(this, other);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => Name.ToString();
public string TargetIdentifier => this.innerReference.TargetIdentifier;
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/Remote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace GitVersion
{
internal sealed class Remote : IRemote
{
private static readonly LambdaEqualityHelper<IRemote> equalityHelper = new(x => x?.Name);
private static readonly LambdaEqualityHelper<IRemote> equalityHelper = new(x => x.Name);
private static readonly LambdaKeyComparer<IRemote, string> comparerHelper = new(x => x.Name);

private readonly LibGit2Sharp.Remote innerRemote;

internal Remote(LibGit2Sharp.Remote remote) => this.innerRemote = remote;

public int CompareTo(IRemote other) => comparerHelper.Compare(this, other);
public bool Equals(IRemote other) => equalityHelper.Equals(this, other);
public bool Equals(IRemote? other) => equalityHelper.Equals(this, other);
public override bool Equals(object obj) => Equals((obj as IRemote)!);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => Name;
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.LibGit2Sharp/Git/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace GitVersion
{
internal sealed class Tag : ITag
{
private static readonly LambdaEqualityHelper<ITag> equalityHelper = new(x => x?.Name.Canonical);
private static readonly LambdaEqualityHelper<ITag> equalityHelper = new(x => x.Name.Canonical);
private static readonly LambdaKeyComparer<ITag, string> comparerHelper = new(x => x.Name.Canonical);

private readonly LibGit2Sharp.Tag innerTag;
Expand All @@ -17,7 +17,7 @@ internal Tag(LibGit2Sharp.Tag tag)
public ReferenceName Name { get; }

public int CompareTo(ITag other) => comparerHelper.Compare(this, other);
public bool Equals(ITag other) => equalityHelper.Equals(this, other);
public bool Equals(ITag? other) => equalityHelper.Equals(this, other);
public override bool Equals(object obj) => Equals((obj as ITag)!);
public override int GetHashCode() => equalityHelper.GetHashCode(this);
public override string ToString() => Name.ToString();
Expand Down