From bdcfd1b30d730d77c1415e19ba423cb3fff98617 Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 9 Jan 2023 13:00:05 +0100 Subject: [PATCH 1/2] #3334 - re-target to .net6.0 and .net7.0 in place of netstandard2.0 --- src/Directory.Build.props | 2 + src/GitTools.Testing/GitTools.Testing.csproj | 1 - .../GitVersion.App.Tests.csproj | 2 - src/GitVersion.App/GitVersion.App.csproj | 1 - .../GitVersion.Core.Tests.csproj | 2 - .../CallerArgumentExpressionAttribute.cs | 25 --- .../Extensions/NullableAttributes.cs | 147 ------------------ src/GitVersion.Core/GitVersion.Core.csproj | 27 ++-- src/GitVersion.Core/Helpers/ProcessHelper.cs | 1 - .../GitVersion.LibGit2Sharp.csproj | 4 - .../GitVersion.MsBuild.Tests.csproj | 2 - .../GitVersion.MsBuild.csproj | 2 - src/GitVersion.MsBuild/nuget-files.props | 14 +- 13 files changed, 22 insertions(+), 208 deletions(-) delete mode 100644 src/GitVersion.Core/Extensions/CallerArgumentExpressionAttribute.cs delete mode 100644 src/GitVersion.Core/Extensions/NullableAttributes.cs diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 10aa09350b..4f2616d3e0 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,5 +1,7 @@ + net6.0;net7.0 + $([System.DateTime]::Today.Year) GitTools and Contributors Copyright GitTools $(EndYear). diff --git a/src/GitTools.Testing/GitTools.Testing.csproj b/src/GitTools.Testing/GitTools.Testing.csproj index a19fdd5b88..3a6c88aa38 100644 --- a/src/GitTools.Testing/GitTools.Testing.csproj +++ b/src/GitTools.Testing/GitTools.Testing.csproj @@ -1,6 +1,5 @@  - netstandard2.0 false diff --git a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj index 294d2c0b01..c66da8eeee 100644 --- a/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj +++ b/src/GitVersion.App.Tests/GitVersion.App.Tests.csproj @@ -1,7 +1,5 @@ - net6.0;net7.0 - true diff --git a/src/GitVersion.App/GitVersion.App.csproj b/src/GitVersion.App/GitVersion.App.csproj index 6e1aa25731..3522236520 100644 --- a/src/GitVersion.App/GitVersion.App.csproj +++ b/src/GitVersion.App/GitVersion.App.csproj @@ -4,7 +4,6 @@ Exe GitVersion gitversion - net6.0;net7.0 AnyCPU MIT diff --git a/src/GitVersion.Core.Tests/GitVersion.Core.Tests.csproj b/src/GitVersion.Core.Tests/GitVersion.Core.Tests.csproj index 23d088dfbc..49b649f9eb 100644 --- a/src/GitVersion.Core.Tests/GitVersion.Core.Tests.csproj +++ b/src/GitVersion.Core.Tests/GitVersion.Core.Tests.csproj @@ -1,8 +1,6 @@ - net6.0;net7.0 - full false true diff --git a/src/GitVersion.Core/Extensions/CallerArgumentExpressionAttribute.cs b/src/GitVersion.Core/Extensions/CallerArgumentExpressionAttribute.cs deleted file mode 100644 index d5408867aa..0000000000 --- a/src/GitVersion.Core/Extensions/CallerArgumentExpressionAttribute.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace System.Runtime.CompilerServices; - -#if !NET6_0 - -/// -/// Allows capturing of the expressions passed to a method. -/// -[AttributeUsage(AttributeTargets.Parameter)] -public sealed class CallerArgumentExpressionAttribute : Attribute -{ - /// - /// Initializes a new instance of the class. - /// - /// The name of the targeted parameter. - public CallerArgumentExpressionAttribute(string parameterName) => this.ParameterName = parameterName; - - /// - /// Gets the target parameter name of the CallerArgumentExpression. - /// - /// - /// The name of the targeted parameter of the CallerArgumentExpression. - /// - public string ParameterName { get; } -} -#endif diff --git a/src/GitVersion.Core/Extensions/NullableAttributes.cs b/src/GitVersion.Core/Extensions/NullableAttributes.cs deleted file mode 100644 index 65c7bebbb1..0000000000 --- a/src/GitVersion.Core/Extensions/NullableAttributes.cs +++ /dev/null @@ -1,147 +0,0 @@ -// This was copied from https://github.com/dotnet/coreclr/blob/60f1e6265bd1039f023a82e0643b524d6aaf7845/src/System.Private.CoreLib/shared/System/Diagnostics/CodeAnalysis/NullableAttributes.cs -// and updated to have the scope of the attributes be internal. - -#pragma warning disable CA1019 // Define accessors for attribute arguments - -namespace System.Diagnostics.CodeAnalysis; -#if !NETCOREAPP - -/// Specifies that null is allowed as an input even if the corresponding type disallows it. -[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] -internal sealed class AllowNullAttribute : Attribute { } - -/// Specifies that null is disallowed as an input even if the corresponding type allows it. -[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)] -internal sealed class DisallowNullAttribute : Attribute { } - -/// Specifies that an output may be null even if the corresponding type disallows it. -[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)] -internal sealed class MaybeNullAttribute : Attribute { } - -/// Specifies that an output will not be null even if the corresponding type allows it. -[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)] -internal sealed class NotNullAttribute : Attribute { } - -/// Specifies that when a method returns , the parameter may be null even if the corresponding type disallows it. -[AttributeUsage(AttributeTargets.Parameter)] -internal sealed class MaybeNullWhenAttribute : Attribute -{ - /// Initializes the attribute with the specified return value condition. - /// - /// The return value condition. If the method returns this value, the associated parameter may be null. - /// - public MaybeNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - - /// Gets the return value condition. - public bool ReturnValue { get; } -} - -/// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. -[AttributeUsage(AttributeTargets.Parameter)] -internal sealed class NotNullWhenAttribute : Attribute -{ - /// Initializes the attribute with the specified return value condition. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; - - /// Gets the return value condition. - public bool ReturnValue { get; } -} - -/// Specifies that the output will be non-null if the named parameter is non-null. -[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue, AllowMultiple = true)] -internal sealed class NotNullIfNotNullAttribute : Attribute -{ - /// Initializes the attribute with the associated parameter name. - /// - /// The associated parameter name. The output will be non-null if the argument to the parameter specified is non-null. - /// - public NotNullIfNotNullAttribute(string parameterName) => ParameterName = parameterName; - - /// Gets the associated parameter name. - public string ParameterName { get; } -} - -/// Applied to a method that will never return under any circumstance. -[AttributeUsage(AttributeTargets.Method, Inherited = false)] -internal sealed class DoesNotReturnAttribute : Attribute { } - -/// Specifies that the method will not return if the associated Boolean parameter is passed the specified value. -[AttributeUsage(AttributeTargets.Parameter)] -internal sealed class DoesNotReturnIfAttribute : Attribute -{ - /// Initializes the attribute with the specified parameter value. - /// - /// The condition parameter value. Code after the method will be considered unreachable by diagnostics if the argument to - /// the associated parameter matches this value. - /// - public DoesNotReturnIfAttribute(bool parameterValue) => ParameterValue = parameterValue; - - /// Gets the condition parameter value. - public bool ParameterValue { get; } -} - -#endif - -#if !NETCOREAPP || NETCOREAPP3_1 - -/// Specifies that the method or property will ensure that the listed field and property members have not-null values. -[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] -internal sealed class MemberNotNullAttribute : Attribute -{ - /// Initializes the attribute with a field or property member. - /// - /// The field or property member that is promised to be not-null. - /// - public MemberNotNullAttribute(string member) => Members = new[] { member }; - - /// Initializes the attribute with the list of field and property members. - /// - /// The list of field and property members that are promised to be not-null. - /// - public MemberNotNullAttribute(params string[] members) => Members = members; - - /// Gets field or property member names. - public string[] Members { get; } -} - -/// Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition. -[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] -internal sealed class MemberNotNullWhenAttribute : Attribute -{ - /// Initializes the attribute with the specified return value condition and a field or property member. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - /// - /// The field or property member that is promised to be not-null. - /// - public MemberNotNullWhenAttribute(bool returnValue, string member) - { - ReturnValue = returnValue; - Members = new[] { member }; - } - - /// Initializes the attribute with the specified return value condition and list of field and property members. - /// - /// The return value condition. If the method returns this value, the associated parameter will not be null. - /// - /// - /// The list of field and property members that are promised to be not-null. - /// - public MemberNotNullWhenAttribute(bool returnValue, params string[] members) - { - ReturnValue = returnValue; - Members = members; - } - - /// Gets the return value condition. - public bool ReturnValue { get; } - - /// Gets field or property member names. - public string[] Members { get; } -} - -#endif diff --git a/src/GitVersion.Core/GitVersion.Core.csproj b/src/GitVersion.Core/GitVersion.Core.csproj index 809cf8db21..4d8e00a35d 100644 --- a/src/GitVersion.Core/GitVersion.Core.csproj +++ b/src/GitVersion.Core/GitVersion.Core.csproj @@ -1,7 +1,6 @@ - netstandard2.0 GitVersion bin\$(Configuration)\GitVersionCore.xml @@ -14,26 +13,26 @@ - - + + - - - - + + + + - - - - + + + + - - - + + + diff --git a/src/GitVersion.Core/Helpers/ProcessHelper.cs b/src/GitVersion.Core/Helpers/ProcessHelper.cs index cbac47cd03..68d5d2de5c 100644 --- a/src/GitVersion.Core/Helpers/ProcessHelper.cs +++ b/src/GitVersion.Core/Helpers/ProcessHelper.cs @@ -1,6 +1,5 @@ using System.ComponentModel; using System.Runtime.InteropServices; -using GitVersion.Extensions; namespace GitVersion.Helpers; diff --git a/src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj b/src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj index 7b0778d9c3..cf74339e6b 100644 --- a/src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj +++ b/src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj @@ -1,9 +1,5 @@ - - netstandard2.0 - - diff --git a/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj b/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj index 1636b1aaf6..2c5681be9b 100644 --- a/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj +++ b/src/GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj @@ -1,8 +1,6 @@ - net6.0;net7.0 - true diff --git a/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj b/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj index 91fe0c2154..9e91390ac5 100644 --- a/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj +++ b/src/GitVersion.MsBuild/GitVersion.MsBuild.csproj @@ -1,8 +1,6 @@ - netstandard2.0 - GitVersion.MsBuild GitVersionMsBuild 0.0.1-alpha-0001 diff --git a/src/GitVersion.MsBuild/nuget-files.props b/src/GitVersion.MsBuild/nuget-files.props index 5c53cb2806..1f72446084 100644 --- a/src/GitVersion.MsBuild/nuget-files.props +++ b/src/GitVersion.MsBuild/nuget-files.props @@ -7,13 +7,13 @@ tools/net7.0 - - - + + + - - - - + + + + From 7da308cffad12d1539fb1f0a7891208831e92344 Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 17 Feb 2023 23:56:01 +0100 Subject: [PATCH 2/2] #3334 - fix nullable warnings --- ...nfigNextVersionBaseVersionStrategyTests.cs | 2 ++ .../MergeMessageBaseVersionStrategyTests.cs | 4 +++ ...ionInBranchNameBaseVersionStrategyTests.cs | 10 ++++++++ src/GitVersion.Core/Core/GitVersionModule.cs | 5 +++- src/GitVersion.Core/Core/MergeCommitFinder.cs | 8 +++--- .../Extensions/CommonExtensions.cs | 8 ++---- .../Extensions/DictionaryExtensions.cs | 3 ++- .../Extensions/ObjectExtensions.cs | 4 +-- .../Extensions/ServiceCollectionExtensions.cs | 2 +- src/GitVersion.Core/Git/ReferenceName.cs | 4 +-- .../OutputVariables/VersionVariables.cs | 4 ++- .../VersionStrategyModule.cs | 2 +- .../IncrementStrategyFinder.cs | 25 +++++++++---------- .../VersionCalculation/NextVersion.cs | 8 +++--- .../NextVersionCalculator.cs | 16 +++++++----- .../SemanticVersioning/SemanticVersion.cs | 2 +- .../SemanticVersionBuildMetaData.cs | 2 +- .../VersionConverters/TemplateManager.cs | 9 +++---- src/GitVersion.LibGit2Sharp/Git/Branch.cs | 4 +-- src/GitVersion.LibGit2Sharp/Git/Commit.cs | 4 +-- src/GitVersion.LibGit2Sharp/Git/GitObject.cs | 4 +-- src/GitVersion.LibGit2Sharp/Git/ObjectId.cs | 4 +-- src/GitVersion.LibGit2Sharp/Git/RefSpec.cs | 4 +-- src/GitVersion.LibGit2Sharp/Git/Reference.cs | 4 +-- src/GitVersion.LibGit2Sharp/Git/Remote.cs | 4 +-- src/GitVersion.LibGit2Sharp/Git/Tag.cs | 4 +-- 26 files changed, 85 insertions(+), 65 deletions(-) diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs index 1f48aa2e24..6db52ed9f4 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/ConfigNextVersionBaseVersionStrategyTests.cs @@ -49,6 +49,8 @@ public void ConfigNextVersionTest(string nextVersion, string expectedVersion) var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit()); var branchConfiguration = context.Configuration.GetBranchConfiguration(branchMock); var effectiveConfiguration = new EffectiveConfiguration(context.Configuration, branchConfiguration); + + strategy.ShouldNotBeNull(); return strategy.GetBaseVersions(new(branchMock, effectiveConfiguration)).SingleOrDefault(); } } diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs index 396755a2eb..c3673bf7a4 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs @@ -40,6 +40,8 @@ public void ShouldNotAllowIncrementOfVersion() var context = contextBuilder.ServicesProvider.GetRequiredService>().Value; var branchConfiguration = context.Configuration.GetBranchConfiguration(mockBranch); var effectiveConfiguration = new EffectiveConfiguration(context.Configuration, branchConfiguration); + + strategy.ShouldNotBeNull(); var baseVersion = strategy.GetBaseVersions(new(mockBranch, effectiveConfiguration)).Single(); baseVersion.ShouldIncrement.ShouldBe(false); @@ -173,6 +175,8 @@ private static void AssertMergeMessage(string message, string? expectedVersion, var context = contextBuilder.ServicesProvider.GetRequiredService>().Value; var branchConfiguration = context.Configuration.GetBranchConfiguration(mockBranch); var effectiveConfiguration = new EffectiveConfiguration(context.Configuration, branchConfiguration); + + strategy.ShouldNotBeNull(); var baseVersion = strategy.GetBaseVersions(new(mockBranch, effectiveConfiguration)).SingleOrDefault(); if (expectedVersion == null) diff --git a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs index da49ec0d21..cf46317704 100644 --- a/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs +++ b/src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs @@ -25,6 +25,8 @@ public void CanTakeVersionFromNameOfReleaseBranch(string branchName, string expe var configuration = GitFlowConfigurationBuilder.New.Build(); var branchConfiguration = configuration.GetBranchConfiguration(branchName); var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration); + + strategy.ShouldNotBeNull(); var baseVersion = strategy.GetBaseVersions(new(gitRepository.FindBranch(branchName)!, effectiveConfiguration)).Single(); baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion); @@ -45,6 +47,8 @@ public void ShouldNotTakeVersionFromNameOfNonReleaseBranch(string branchName) var configuration = GitFlowConfigurationBuilder.New.Build(); var branchConfiguration = configuration.GetBranchConfiguration(branchName); var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration); + + strategy.ShouldNotBeNull(); var baseVersions = strategy.GetBaseVersions(new(gitRepository.FindBranch(branchName)!, effectiveConfiguration)); baseVersions.ShouldBeEmpty(); @@ -67,6 +71,9 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s var configuration = GitFlowConfigurationBuilder.New.Build(); var branchConfiguration = configuration.GetBranchConfiguration(branchName); var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration); + + strategy.ShouldNotBeNull(); + var baseVersion = strategy.GetBaseVersions(new(gitRepository.FindBranch(branchName)!, effectiveConfiguration)).Single(); baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion); @@ -90,6 +97,9 @@ public void CanTakeVersionFromNameOfRemoteReleaseBranch(string branchName, strin var configuration = GitFlowConfigurationBuilder.New.Build(); var branchConfiguration = configuration.GetBranchConfiguration(branchName); var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration); + + strategy.ShouldNotBeNull(); + var baseVersion = strategy.GetBaseVersions(new(gitRepository.FindBranch(branchName)!, effectiveConfiguration)).Single(); baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion); diff --git a/src/GitVersion.Core/Core/GitVersionModule.cs b/src/GitVersion.Core/Core/GitVersionModule.cs index 3762aeb2ec..f9b24a65e0 100644 --- a/src/GitVersion.Core/Core/GitVersionModule.cs +++ b/src/GitVersion.Core/Core/GitVersionModule.cs @@ -1,3 +1,4 @@ +using GitVersion.Extensions; using Microsoft.Extensions.DependencyInjection; namespace GitVersion; @@ -6,8 +7,10 @@ public abstract class GitVersionModule : IGitVersionModule { public abstract void RegisterTypes(IServiceCollection services); - protected static IEnumerable FindAllDerivedTypes(Assembly assembly) + protected static IEnumerable FindAllDerivedTypes(Assembly? assembly) { + assembly.NotNull(); + var derivedType = typeof(T); return assembly.GetTypes().Where(t => t != derivedType && derivedType.IsAssignableFrom(t)); } diff --git a/src/GitVersion.Core/Core/MergeCommitFinder.cs b/src/GitVersion.Core/Core/MergeCommitFinder.cs index a37cd031ab..11e682dc81 100644 --- a/src/GitVersion.Core/Core/MergeCommitFinder.cs +++ b/src/GitVersion.Core/Core/MergeCommitFinder.cs @@ -8,7 +8,7 @@ internal class MergeCommitFinder { private readonly IEnumerable excludedBranches; private readonly ILog log; - private readonly Dictionary> mergeBaseCommitsCache = new(); + private readonly Dictionary> mergeBaseCommitsCache = new(); private readonly RepositoryStore repositoryStore; private readonly GitVersionConfiguration configuration; @@ -24,10 +24,10 @@ public IEnumerable FindMergeCommitsFor(IBranch branch) { branch = branch.NotNull(); - if (this.mergeBaseCommitsCache.ContainsKey(branch)) + if (this.mergeBaseCommitsCache.TryGetValue(branch, out var mergeCommitsFor)) { - this.log.Debug($"Cache hit for getting merge commits for branch {branch?.Name.Canonical}."); - return this.mergeBaseCommitsCache[branch]; + this.log.Debug($"Cache hit for getting merge commits for branch {branch.Name.Canonical}."); + return mergeCommitsFor; } var branchMergeBases = FindMergeBases(branch) diff --git a/src/GitVersion.Core/Extensions/CommonExtensions.cs b/src/GitVersion.Core/Extensions/CommonExtensions.cs index 5cd5018df9..616fe30cd0 100644 --- a/src/GitVersion.Core/Extensions/CommonExtensions.cs +++ b/src/GitVersion.Core/Extensions/CommonExtensions.cs @@ -15,9 +15,7 @@ public static string NotNullOrEmpty([NotNull] this string? value, [CallerArgumen throw new ArgumentException("The parameter is null or empty.", name); } -#pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - return value!; -#pragma warning restore CS8777 // Parameter must have a non-null value when exiting. + return value; } public static string NotNullOrWhitespace([NotNull] this string? value, [CallerArgumentExpression("value")] string name = "") @@ -27,8 +25,6 @@ public static string NotNullOrWhitespace([NotNull] this string? value, [CallerAr throw new ArgumentException("The parameter is null or empty or contains only white space.", name); } -#pragma warning disable CS8777 // Parameter must have a non-null value when exiting. - return value!; -#pragma warning restore CS8777 // Parameter must have a non-null value when exiting. + return value; } } diff --git a/src/GitVersion.Core/Extensions/DictionaryExtensions.cs b/src/GitVersion.Core/Extensions/DictionaryExtensions.cs index ade4ffb7c6..7a1ab3723c 100644 --- a/src/GitVersion.Core/Extensions/DictionaryExtensions.cs +++ b/src/GitVersion.Core/Extensions/DictionaryExtensions.cs @@ -6,7 +6,8 @@ public static TValue GetOrAdd(this IDictionary dict, { if (dict is null) throw new ArgumentNullException(nameof(dict)); if (getValue is null) throw new ArgumentNullException(nameof(getValue)); - if (!dict.TryGetValue(key, out TValue value)) + + if (!dict.TryGetValue(key, out var value)) { value = getValue(); dict.Add(key, value); diff --git a/src/GitVersion.Core/Extensions/ObjectExtensions.cs b/src/GitVersion.Core/Extensions/ObjectExtensions.cs index 85857a6ef0..ba9db81686 100644 --- a/src/GitVersion.Core/Extensions/ObjectExtensions.cs +++ b/src/GitVersion.Core/Extensions/ObjectExtensions.cs @@ -16,11 +16,11 @@ public static void Deconstruct( value = kvp.Value; } - public static IEnumerable> GetProperties(this object obj) + public static Dictionary GetProperties(this object obj) { var type = typeof(string); return obj.GetType().GetProperties() .Where(p => p.PropertyType == type && !p.GetIndexParameters().Any() && !p.GetCustomAttributes(typeof(ReflectionIgnoreAttribute), false).Any()) - .Select(p => new KeyValuePair(p.Name, (string)p.GetValue(obj, null))); + .ToDictionary(p => p.Name, p => Convert.ToString(p.GetValue(obj, null))!); } } diff --git a/src/GitVersion.Core/Extensions/ServiceCollectionExtensions.cs b/src/GitVersion.Core/Extensions/ServiceCollectionExtensions.cs index d4d6467f3d..153bf20e53 100644 --- a/src/GitVersion.Core/Extensions/ServiceCollectionExtensions.cs +++ b/src/GitVersion.Core/Extensions/ServiceCollectionExtensions.cs @@ -11,5 +11,5 @@ public static IServiceCollection AddModule(this IServiceCollection serviceCollec } public static TService GetServiceForType(this IServiceProvider serviceProvider) => - serviceProvider.GetServices().SingleOrDefault(t => t?.GetType() == typeof(TType)); + serviceProvider.GetServices().Single(t => t?.GetType() == typeof(TType)); } diff --git a/src/GitVersion.Core/Git/ReferenceName.cs b/src/GitVersion.Core/Git/ReferenceName.cs index 6787705285..b504c4a8a3 100644 --- a/src/GitVersion.Core/Git/ReferenceName.cs +++ b/src/GitVersion.Core/Git/ReferenceName.cs @@ -56,8 +56,8 @@ public static ReferenceName Parse(string canonicalName) public bool IsPullRequest { get; } 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 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); public override string ToString() => Friendly; diff --git a/src/GitVersion.Core/OutputVariables/VersionVariables.cs b/src/GitVersion.Core/OutputVariables/VersionVariables.cs index d82d492cbc..97f0da6df3 100644 --- a/src/GitVersion.Core/OutputVariables/VersionVariables.cs +++ b/src/GitVersion.Core/OutputVariables/VersionVariables.cs @@ -1,5 +1,6 @@ using System.Text.Encodings.Web; using System.Text.Json; +using GitVersion.Extensions; using GitVersion.Helpers; using YamlDotNet.Serialization; using static GitVersion.Extensions.ObjectExtensions; @@ -115,7 +116,8 @@ private static VersionVariables FromDictionary(IEnumerable properties?.Single(v => string.Equals(v.Key, p.Name, StringComparison.InvariantCultureIgnoreCase)).Value) .Cast() .ToArray(); - return (VersionVariables)Activator.CreateInstance(type, ctorArgs); + var instance = Activator.CreateInstance(type, ctorArgs).NotNull(); + return (VersionVariables)instance; } public static VersionVariables FromJson(string json) diff --git a/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionStrategyModule.cs b/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionStrategyModule.cs index aa5b8a6d26..1721e51100 100644 --- a/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionStrategyModule.cs +++ b/src/GitVersion.Core/VersionCalculation/BaseVersionCalculators/VersionStrategyModule.cs @@ -7,7 +7,7 @@ public class VersionStrategyModule : GitVersionModule public override void RegisterTypes(IServiceCollection services) { var versionStrategies = FindAllDerivedTypes(Assembly.GetAssembly(GetType())) - .Where(x => !x.IsAbstract && !x.IsInterface); + .Where(x => x is { IsAbstract: false, IsInterface: false }); foreach (var versionStrategy in versionStrategies) { diff --git a/src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs b/src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs index 73b72b4ccf..018b87b23e 100644 --- a/src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs +++ b/src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs @@ -30,7 +30,7 @@ public VersionField DetermineIncrementedField(GitVersionContext context, BaseVer { configuration.NotNull(); - var commitMessageIncrement = FindCommitMessageIncrement(this.repository, context, configuration, baseVersion.BaseVersionSource); + var commitMessageIncrement = FindCommitMessageIncrement(context, configuration, baseVersion.BaseVersionSource); var defaultIncrement = configuration.Increment.ToVersionField(); @@ -73,8 +73,7 @@ public VersionField DetermineIncrementedField(GitVersionContext context, BaseVer : null; } - private VersionField? FindCommitMessageIncrement(IGitRepository repository, GitVersionContext context, - EffectiveConfiguration configuration, ICommit? baseCommit) + private VersionField? FindCommitMessageIncrement(GitVersionContext context, EffectiveConfiguration configuration, ICommit? baseCommit) { if (baseCommit == null) return null; @@ -83,7 +82,7 @@ public VersionField DetermineIncrementedField(GitVersionContext context, BaseVer return null; } - var commits = GetIntermediateCommits(repository, baseCommit, context.CurrentCommit); + var commits = GetIntermediateCommits(baseCommit, context.CurrentCommit); // consider commit messages since latest tag only (see #3071) var tags = new HashSet(repository.Tags.Select(t => t.TargetSha)); @@ -106,33 +105,33 @@ private static Regex TryGetRegexOrDefault(string? messageRegex, Regex defaultReg : CompiledRegexCache.GetOrAdd(messageRegex, pattern => new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)); /// - /// Get the sequence of commits in a between a (exclusive) + /// Get the sequence of commits in a repository between a (exclusive) /// and a particular (inclusive) /// - private IEnumerable GetIntermediateCommits(IGitRepository repository, IGitObject baseCommit, ICommit? headCommit) + private IEnumerable GetIntermediateCommits(IGitObject baseCommit, ICommit? headCommit) { - var map = GetHeadCommitsMap(repository, headCommit); + var map = GetHeadCommitsMap(headCommit); if (!map.TryGetValue(baseCommit.Sha, out var baseIndex)) return Enumerable.Empty(); var commitAfterBaseIndex = baseIndex + 1; - var headCommits = GetHeadCommits(repository, headCommit); + var headCommits = GetHeadCommits(headCommit); return new ArraySegment(headCommits, commitAfterBaseIndex, headCommits.Length - commitAfterBaseIndex); } /// /// Get a mapping of commit shas to their zero-based position in the sequence of commits from the beginning of a - /// to a particular + /// repository to a particular /// - private Dictionary GetHeadCommitsMap(IGitRepository repository, ICommit? headCommit) => + private Dictionary GetHeadCommitsMap(ICommit? headCommit) => this.headCommitsMapCache.GetOrAdd(headCommit?.Sha ?? "NULL", () => - GetHeadCommits(repository, headCommit) + GetHeadCommits(headCommit) .Select((commit, index) => (commit.Sha, Index: index)) .ToDictionary(t => t.Sha, t => t.Index)); /// - /// Get the sequence of commits from the beginning of a to a particular + /// Get the sequence of commits from the beginning of a repository to a particular /// (inclusive) /// - private ICommit[] GetHeadCommits(IGitRepository repository, ICommit? headCommit) => + private ICommit[] GetHeadCommits(ICommit? headCommit) => this.headCommitsCache.GetOrAdd(headCommit?.Sha ?? "NULL", () => GetCommitsReacheableFromHead(repository, headCommit).ToArray()); diff --git a/src/GitVersion.Core/VersionCalculation/NextVersion.cs b/src/GitVersion.Core/VersionCalculation/NextVersion.cs index ab59d6a1e6..d66d9aa63b 100644 --- a/src/GitVersion.Core/VersionCalculation/NextVersion.cs +++ b/src/GitVersion.Core/VersionCalculation/NextVersion.cs @@ -26,9 +26,9 @@ public NextVersion(SemanticVersion incrementedVersion, BaseVersion baseVersion, Branch = branch.NotNull(); } - public int CompareTo(NextVersion other) => IncrementedVersion.CompareTo(other.IncrementedVersion); + public int CompareTo(NextVersion? other) => IncrementedVersion.CompareTo(other?.IncrementedVersion); - public static bool operator ==(NextVersion left, NextVersion right) => left.CompareTo(right) == 0; + public static bool operator ==(NextVersion left, NextVersion? right) => left.CompareTo(right) == 0; public static bool operator !=(NextVersion left, NextVersion right) => left.CompareTo(right) != 0; @@ -40,9 +40,9 @@ public NextVersion(SemanticVersion incrementedVersion, BaseVersion baseVersion, public static bool operator >=(NextVersion left, NextVersion right) => left.CompareTo(right) >= 0; - public bool Equals(NextVersion other) => this == other; + public bool Equals(NextVersion? other) => this == other; - public override bool Equals(object other) => other is NextVersion nextVersion && Equals(nextVersion); + public override bool Equals(object? other) => other is NextVersion nextVersion && Equals(nextVersion); public override string ToString() => $"{BaseVersion} | {IncrementedVersion}"; diff --git a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs index f033f567ed..f846586bad 100644 --- a/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs +++ b/src/GitVersion.Core/VersionCalculation/NextVersionCalculator.cs @@ -52,7 +52,7 @@ public virtual NextVersion FindVersion() if (Context.IsCurrentCommitTagged) { // Will always be 0, don't bother with the +0 on tags - var semanticVersionBuildMetaData = this.mainlineVersionCalculator.CreateVersionBuildMetaData(Context.CurrentCommit!); + var semanticVersionBuildMetaData = this.mainlineVersionCalculator.CreateVersionBuildMetaData(Context.CurrentCommit); semanticVersionBuildMetaData.CommitsSinceTag = null; var semanticVersion = new SemanticVersion(Context.CurrentCommitTaggedVersion) { BuildMetaData = semanticVersionBuildMetaData }; taggedSemanticVersion = semanticVersion; @@ -135,7 +135,7 @@ private void UpdatePreReleaseTag(EffectiveBranchConfiguration configuration, Sem if (lastTag != null && MajorMinorPatchEqual(lastTag, semanticVersion) && lastTag.HasPreReleaseTagWithLabel) { - number = lastTag.PreReleaseTag!.Number + 1; + number = lastTag.PreReleaseTag?.Number + 1; } number ??= 1; @@ -143,7 +143,8 @@ private void UpdatePreReleaseTag(EffectiveBranchConfiguration configuration, Sem semanticVersion.PreReleaseTag = new SemanticVersionPreReleaseTag(tagToUse, number); } - private static bool MajorMinorPatchEqual(SemanticVersion lastTag, SemanticVersion baseVersion) => lastTag.Major == baseVersion.Major && lastTag.Minor == baseVersion.Minor && lastTag.Patch == baseVersion.Patch; + private static bool MajorMinorPatchEqual(SemanticVersion lastTag, SemanticVersion baseVersion) => + lastTag.Major == baseVersion.Major && lastTag.Minor == baseVersion.Minor && lastTag.Patch == baseVersion.Patch; private NextVersion Calculate(IBranch branch, GitVersionConfiguration configuration) { @@ -152,6 +153,8 @@ private NextVersion Calculate(IBranch branch, GitVersionConfiguration configurat var nextVersions = GetNextVersions(branch, configuration).ToArray(); var maxVersion = nextVersions.Max(); + maxVersion.NotNull(); + var matchingVersionsOnceIncremented = nextVersions .Where(v => v.BaseVersion.BaseVersionSource != null && v.IncrementedVersion == maxVersion.IncrementedVersion) .ToList(); @@ -192,13 +195,14 @@ static NextVersion CompareVersions( filteredVersions = filteredVersions.Where(v => !v.BaseVersion.SemanticVersion.HasPreReleaseTagWithLabel); } - var version = filteredVersions + var versions = filteredVersions as NextVersion[] ?? filteredVersions.ToArray(); + var version = versions .Where(v => v.BaseVersion.BaseVersionSource != null) .OrderByDescending(v => v.IncrementedVersion) - .ThenByDescending(v => v.BaseVersion.BaseVersionSource!.When) + .ThenByDescending(v => v.BaseVersion.BaseVersionSource?.When) .FirstOrDefault(); - version ??= filteredVersions.Where(v => v.BaseVersion.BaseVersionSource == null) + version ??= versions.Where(v => v.BaseVersion.BaseVersionSource == null) .OrderByDescending(v => v.IncrementedVersion) .First(); latestBaseVersionSource = version.BaseVersion.BaseVersionSource; diff --git a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs index 3394a66e44..5045e8afec 100644 --- a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs +++ b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersion.cs @@ -208,7 +208,7 @@ private static bool TryParseLoose(string version, [NotNullWhen(true)] out Semant return true; } - public int CompareTo(SemanticVersion value) => CompareTo(value, true); + public int CompareTo(SemanticVersion? value) => CompareTo(value, true); public int CompareTo(SemanticVersion? value, bool includePrerelease) { diff --git a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionBuildMetaData.cs b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionBuildMetaData.cs index 30c11d3ff1..adf85c660b 100644 --- a/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionBuildMetaData.cs +++ b/src/GitVersion.Core/VersionCalculation/SemanticVersioning/SemanticVersionBuildMetaData.cs @@ -54,7 +54,7 @@ public SemanticVersionBuildMetaData(SemanticVersionBuildMetaData? buildMetaData) this.UncommittedChanges = buildMetaData?.UncommittedChanges ?? 0; } - public override bool Equals(object obj) => Equals(obj as SemanticVersionBuildMetaData); + public override bool Equals(object? obj) => Equals(obj as SemanticVersionBuildMetaData); public bool Equals(SemanticVersionBuildMetaData? other) => EqualityHelper.Equals(this, other); diff --git a/src/GitVersion.Core/VersionConverters/TemplateManager.cs b/src/GitVersion.Core/VersionConverters/TemplateManager.cs index ebae681484..067f045de0 100644 --- a/src/GitVersion.Core/VersionConverters/TemplateManager.cs +++ b/src/GitVersion.Core/VersionConverters/TemplateManager.cs @@ -15,8 +15,8 @@ internal class TemplateManager public TemplateManager(TemplateType templateType) { - this.templates = GetEmbeddedTemplates(templateType, "Templates").ToDictionary(Path.GetExtension, v => v, StringComparer.OrdinalIgnoreCase); - this.addFormats = GetEmbeddedTemplates(templateType, "AddFormats").ToDictionary(Path.GetExtension, v => v, StringComparer.OrdinalIgnoreCase); + this.templates = GetEmbeddedTemplates(templateType, "Templates").ToDictionary(file => Path.GetExtension(file)!, v => v, StringComparer.OrdinalIgnoreCase); + this.addFormats = GetEmbeddedTemplates(templateType, "AddFormats").ToDictionary(file => Path.GetExtension(file)!, v => v, StringComparer.OrdinalIgnoreCase); } public string? GetTemplateFor(string fileExtension) @@ -28,7 +28,7 @@ public TemplateManager(TemplateType templateType) string? result = null; - if (this.templates.TryGetValue(fileExtension, out var template) && template != null) + if (this.templates.TryGetValue(fileExtension, out var template)) { result = template.ReadAsStringFromEmbeddedResource(); } @@ -45,7 +45,7 @@ public TemplateManager(TemplateType templateType) string? result = null; - if (this.addFormats.TryGetValue(fileExtension, out var addFormat) && addFormat != null) + if (this.addFormats.TryGetValue(fileExtension, out var addFormat)) { result = addFormat.ReadAsStringFromEmbeddedResource().TrimEnd('\r', '\n'); } @@ -65,7 +65,6 @@ public bool IsSupported(string fileExtension) private static IEnumerable GetEmbeddedTemplates(TemplateType templateType, string templateCategory) { - var assembly = typeof(TemplateManager).Assembly; foreach (var name in assembly.GetManifestResourceNames()) diff --git a/src/GitVersion.LibGit2Sharp/Git/Branch.cs b/src/GitVersion.LibGit2Sharp/Git/Branch.cs index 5cf3265577..f6ed7ebfb7 100644 --- a/src/GitVersion.LibGit2Sharp/Git/Branch.cs +++ b/src/GitVersion.LibGit2Sharp/Git/Branch.cs @@ -25,12 +25,12 @@ internal Branch(LibGit2Sharp.Branch branch) public ReferenceName Name { get; } public ICommit? Tip { get; } public ICommitCollection? Commits { get; } - public int CompareTo(IBranch other) => comparerHelper.Compare(this, other); + public int CompareTo(IBranch? other) => comparerHelper.Compare(this, other); public bool Equals(IBranch? other) => equalityHelper.Equals(this, other); public bool IsDetachedHead => Name.Canonical.Equals("(no branch)", StringComparison.OrdinalIgnoreCase); public bool IsRemote => this.innerBranch.IsRemote; public bool IsTracking => this.innerBranch.IsTracking; - public override bool Equals(object obj) => Equals((obj as IBranch)); + public override bool Equals(object? obj) => Equals((obj as IBranch)); public override int GetHashCode() => equalityHelper.GetHashCode(this); public override string ToString() => Name.ToString(); public static implicit operator LibGit2Sharp.Branch(Branch d) => d.innerBranch; diff --git a/src/GitVersion.LibGit2Sharp/Git/Commit.cs b/src/GitVersion.LibGit2Sharp/Git/Commit.cs index 51505ed7b2..4951b99b2b 100644 --- a/src/GitVersion.LibGit2Sharp/Git/Commit.cs +++ b/src/GitVersion.LibGit2Sharp/Git/Commit.cs @@ -17,12 +17,12 @@ internal Commit(LibGit2Sharp.Commit innerCommit) : base(innerCommit) When = innerCommit.Committer.When; } - public int CompareTo(ICommit other) => comparerHelper.Compare(this, other); + public int CompareTo(ICommit? other) => comparerHelper.Compare(this, other); public bool Equals(ICommit? other) => equalityHelper.Equals(this, other); public IEnumerable Parents { get; } public DateTimeOffset When { get; } public string Message => this.innerCommit.Message; - public override bool Equals(object obj) => Equals((obj as ICommit)); + 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}"; public static implicit operator LibGit2Sharp.Commit(Commit d) => d.innerCommit; diff --git a/src/GitVersion.LibGit2Sharp/Git/GitObject.cs b/src/GitVersion.LibGit2Sharp/Git/GitObject.cs index 535056bdcf..fece8acb9d 100644 --- a/src/GitVersion.LibGit2Sharp/Git/GitObject.cs +++ b/src/GitVersion.LibGit2Sharp/Git/GitObject.cs @@ -15,9 +15,9 @@ internal GitObject(LibGit2Sharp.GitObject innerGitObject) Sha = innerGitObject.Sha; } - public int CompareTo(IGitObject other) => comparerHelper.Compare(this, other); + public int CompareTo(IGitObject? other) => comparerHelper.Compare(this, other); public bool Equals(IGitObject? other) => equalityHelper.Equals(this, other); - public override bool Equals(object obj) => Equals((obj as IGitObject)); + public override bool Equals(object? obj) => Equals((obj as IGitObject)); public override int GetHashCode() => equalityHelper.GetHashCode(this); public override string ToString() => Id.ToString(7); diff --git a/src/GitVersion.LibGit2Sharp/Git/ObjectId.cs b/src/GitVersion.LibGit2Sharp/Git/ObjectId.cs index 74a36ca1e1..8ddc823bd4 100644 --- a/src/GitVersion.LibGit2Sharp/Git/ObjectId.cs +++ b/src/GitVersion.LibGit2Sharp/Git/ObjectId.cs @@ -17,9 +17,9 @@ public ObjectId(string sha) : this(new LibGit2Sharp.ObjectId(sha)) { } - public int CompareTo(IObjectId other) => comparerHelper.Compare(this, other); + public int CompareTo(IObjectId? other) => comparerHelper.Compare(this, other); public bool Equals(IObjectId? other) => equalityHelper.Equals(this, other); - public override bool Equals(object obj) => Equals((obj as IObjectId)); + public override bool Equals(object? obj) => Equals((obj as IObjectId)); public override int GetHashCode() => equalityHelper.GetHashCode(this); public override string ToString() => ToString(7); public static implicit operator LibGit2Sharp.ObjectId(ObjectId d) => d.innerObjectId; diff --git a/src/GitVersion.LibGit2Sharp/Git/RefSpec.cs b/src/GitVersion.LibGit2Sharp/Git/RefSpec.cs index 5cd46bc0a6..fd8ab992c7 100644 --- a/src/GitVersion.LibGit2Sharp/Git/RefSpec.cs +++ b/src/GitVersion.LibGit2Sharp/Git/RefSpec.cs @@ -10,13 +10,13 @@ public class RefSpec : IRefSpec private readonly LibGit2Sharp.RefSpec innerRefSpec; internal RefSpec(LibGit2Sharp.RefSpec refSpec) => this.innerRefSpec = refSpec.NotNull(); - public int CompareTo(IRefSpec other) => comparerHelper.Compare(this, other); + public int CompareTo(IRefSpec? other) => comparerHelper.Compare(this, other); public bool Equals(IRefSpec? other) => equalityHelper.Equals(this, other); public string Specification => this.innerRefSpec.Specification; public RefSpecDirection Direction => (RefSpecDirection)this.innerRefSpec.Direction; public string Source => this.innerRefSpec.Source; public string Destination => this.innerRefSpec.Destination; - public override bool Equals(object obj) => Equals((obj as IRefSpec)); + public override bool Equals(object? obj) => Equals((obj as IRefSpec)); public override int GetHashCode() => equalityHelper.GetHashCode(this); public override string ToString() => Specification; } diff --git a/src/GitVersion.LibGit2Sharp/Git/Reference.cs b/src/GitVersion.LibGit2Sharp/Git/Reference.cs index f88d75e3f2..cc29b520d5 100644 --- a/src/GitVersion.LibGit2Sharp/Git/Reference.cs +++ b/src/GitVersion.LibGit2Sharp/Git/Reference.cs @@ -21,8 +21,8 @@ internal Reference(LibGit2Sharp.Reference reference) public ReferenceName Name { get; } public IObjectId? ReferenceTargetId { get; } - public int CompareTo(IReference other) => comparerHelper.Compare(this, other); - public override bool Equals(object obj) => Equals(obj as IReference); + 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 override int GetHashCode() => equalityHelper.GetHashCode(this); public override string ToString() => Name.ToString(); diff --git a/src/GitVersion.LibGit2Sharp/Git/Remote.cs b/src/GitVersion.LibGit2Sharp/Git/Remote.cs index b92326080c..c004a44d84 100644 --- a/src/GitVersion.LibGit2Sharp/Git/Remote.cs +++ b/src/GitVersion.LibGit2Sharp/Git/Remote.cs @@ -12,7 +12,7 @@ internal sealed class Remote : IRemote internal Remote(LibGit2Sharp.Remote remote) => this.innerRemote = remote.NotNull(); - public int CompareTo(IRemote other) => comparerHelper.Compare(this, other); + public int CompareTo(IRemote? other) => comparerHelper.Compare(this, other); public bool Equals(IRemote? other) => equalityHelper.Equals(this, other); public string Name => this.innerRemote.Name; public string Url => this.innerRemote.Url; @@ -30,7 +30,7 @@ public IEnumerable RefSpecs public IEnumerable FetchRefSpecs => RefSpecs.Where(x => x.Direction == RefSpecDirection.Fetch); public IEnumerable PushRefSpecs => RefSpecs.Where(x => x.Direction == RefSpecDirection.Push); - public override bool Equals(object obj) => Equals((obj as IRemote)); + public override bool Equals(object? obj) => Equals((obj as IRemote)); public override int GetHashCode() => equalityHelper.GetHashCode(this); public override string ToString() => Name; } diff --git a/src/GitVersion.LibGit2Sharp/Git/Tag.cs b/src/GitVersion.LibGit2Sharp/Git/Tag.cs index dd0b83b270..ddcfa92e3b 100644 --- a/src/GitVersion.LibGit2Sharp/Git/Tag.cs +++ b/src/GitVersion.LibGit2Sharp/Git/Tag.cs @@ -17,7 +17,7 @@ internal Tag(LibGit2Sharp.Tag tag) } public ReferenceName Name { get; } - public int CompareTo(ITag other) => comparerHelper.Compare(this, other); + public int CompareTo(ITag? other) => comparerHelper.Compare(this, other); public bool Equals(ITag? other) => equalityHelper.Equals(this, other); public string? TargetSha => this.innerTag.Target.Sha; @@ -33,7 +33,7 @@ internal Tag(LibGit2Sharp.Tag tag) return target is LibGit2Sharp.Commit commit ? new Commit(commit) : null; } - public override bool Equals(object obj) => Equals((obj as ITag)); + public override bool Equals(object? obj) => Equals((obj as ITag)); public override int GetHashCode() => equalityHelper.GetHashCode(this); public override string ToString() => Name.ToString(); }