From e0b8ac78d2cf33e6fc29b5315257159c97ad2a93 Mon Sep 17 00:00:00 2001 From: Louis Seubert Date: Tue, 6 Aug 2024 10:44:40 +0200 Subject: [PATCH 1/4] move msbuild properties default evaluation to targets file This fix ensure that all properties used by these msbuild properties are set by the previouse evalitiuon before computing the default value. --- .../msbuild/tools/GitVersion.MsBuild.props | 5 ----- .../msbuild/tools/GitVersion.MsBuild.targets | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props b/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props index 52048425f1..e1f335e940 100644 --- a/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props +++ b/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props @@ -16,11 +16,6 @@ $(GitVersion_ToolArgments) -nofetch $(GitVersion_ToolArgments) -nonormalize $(GitVersion_ToolArgments) -nocache - - $(TargetFramework) - - dotnet --roll-forward Major "$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))gitversion.dll" - $([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))GitVersion.MsBuild.dll diff --git a/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets b/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets index d5c6f70729..ddc0e54d1e 100644 --- a/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets +++ b/src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets @@ -7,6 +7,10 @@ true true + + $(TargetFramework) + dotnet --roll-forward Major "$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))gitversion.dll" + $([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))GitVersion.MsBuild.dll From 7b741c5571954d76778a619ef15412ef5227d3fb Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Tue, 6 Aug 2024 14:43:34 +0200 Subject: [PATCH 2/4] #4120 - update Breaking Changes, adding info about the removed legacy output variables --- BREAKING_CHANGES.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 9f0db2b22b..ec20701053 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -71,6 +71,19 @@ * When creating a branch with name `hotfix/next` (by using the `GitFlow` workflow) or `release/next` (by the `GitHubFlow` workflow) the resulting version will yield to a patched version per default. * If you have a tag `1.0.0` on `main` and branch from `main` to `release/1.0.1` then the next version number will be `1.1.0` when using the `GitFlow` workflow. This behavior is expected (but different compared to the `GitHubFlow` workflow) because on the `GitFlow` workflow you have an addition branch configuration with name hotfix where `is-release-branch` is set to `true`. That means if you want `1.0.1` as a next version you need to branch to `hotfix/1.0.1` or `hotfix/next`. On the other hand if you use the `GitHubFlow` workflow the next version number will be `1.0.1` because the increment on the `release` branch is set to `Patch`. +### Legacy Output Variables + +The following legacy output variables have been removed in this version: + +* `BuildMetaDataPadded` +* `LegacySemVer` +* `LegacySemVerPadded` +* `NuGetVersionV2` +* `NuGetVersion` +* `NuGetPreReleaseTagV2` +* `NuGetPreReleaseTag` +* `CommitsSinceVersionSourcePadded` + ## v5.0.0 * Version numbers in branches other than `release` branches are no longer From 73c2433aad9cb5e10f406fef2be97acab6ace8ce Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 7 Aug 2024 08:03:24 +0200 Subject: [PATCH 3/4] Remove dependency on "git" cmdline This will simplify the publishing to winget --- src/GitVersion.App/GitVersionExecutor.cs | 10 +++----- .../Extensions/GitToolsTestingExtensions.cs | 10 +++++--- .../Core/GitVersionContextFactory.cs | 3 ++- .../Extensions/GitExtensions.cs | 23 +++---------------- src/GitVersion.Core/PublicAPI.Shipped.txt | 2 +- .../Fixtures/RepositoryFixtureBase.cs | 6 ++--- src/GitVersion.Testing/GitTestExtensions.cs | 4 ++-- .../GitVersion.Testing.csproj | 3 +-- .../Helpers/ProcessHelper.cs | 4 ++-- src/mark-shipped.ps1 | 2 ++ 10 files changed, 26 insertions(+), 41 deletions(-) rename src/{GitVersion.Core => GitVersion.Testing}/Helpers/ProcessHelper.cs (99%) mode change 100644 => 100755 src/mark-shipped.ps1 diff --git a/src/GitVersion.App/GitVersionExecutor.cs b/src/GitVersion.App/GitVersionExecutor.cs index fb2b001135..41bc2d8d0b 100644 --- a/src/GitVersion.App/GitVersionExecutor.cs +++ b/src/GitVersion.App/GitVersionExecutor.cs @@ -82,16 +82,13 @@ private int RunGitVersionTool(GitVersionOptions gitVersionOptions) var error = $"An unexpected error occurred:{PathHelper.NewLine}{exception}"; this.log.Error(error); - this.log.Info("Attempting to show the current git graph (please include in issue): "); - this.log.Info("Showing max of 100 commits"); - try { - GitExtensions.DumpGraph(gitVersionOptions.WorkingDirectory, mess => this.log.Info(mess), 100); + GitExtensions.DumpGraphLog(logMessage => this.log.Info(logMessage)); } catch (Exception dumpGraphException) { - this.log.Error("Couldn't dump the git graph due to the following error: " + dumpGraphException); + this.log.Error($"Couldn't dump the git graph due to the following error: {dumpGraphException}"); } return 1; } @@ -131,8 +128,7 @@ private bool HandleNonMainCommand(GitVersionOptions gitVersionOptions, out int e var workingDirectory = gitVersionOptions.WorkingDirectory; if (gitVersionOptions.Diag) { - this.log.Info("Dumping commit graph: "); - GitExtensions.DumpGraph(workingDirectory, mess => this.log.Info(mess), 100); + GitExtensions.DumpGraphLog(logMessage => this.log.Info(logMessage)); } if (!Directory.Exists(workingDirectory)) diff --git a/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs b/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs index bc753cdaaf..cfd5c713d5 100644 --- a/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs +++ b/src/GitVersion.Core.Tests/Extensions/GitToolsTestingExtensions.cs @@ -30,6 +30,7 @@ public static ICommit CreateMockCommit() commit.When.Returns(when.AddSeconds(1)); return commit; } + public static IBranch CreateMockBranch(string name, params ICommit[] commits) { var branch = Substitute.For(); @@ -55,13 +56,13 @@ public static void DiscoverRepository(this IServiceProvider sp) public static IBranch FindBranch(this IGitRepository repository, string branchName) => repository.Branches.FirstOrDefault(branch => branch.Name.WithoutOrigin == branchName) - ?? throw new GitVersionException($"Branch {branchName} not found"); + ?? throw new GitVersionException($"Branch {branchName} not found"); public static void DumpGraph(this IGitRepository repository, Action? writer = null, int? maxCommits = null) - => GitExtensions.DumpGraph(repository.Path, writer, maxCommits); + => DumpGraph(repository.Path, writer, maxCommits); public static void DumpGraph(this IRepository repository, Action? writer = null, int? maxCommits = null) - => GitExtensions.DumpGraph(repository.ToGitRepository().Path, writer, maxCommits); + => DumpGraph(repository.ToGitRepository().Path, writer, maxCommits); public static GitVersionVariables GetVersion(this RepositoryFixtureBase fixture, IGitVersionConfiguration? configuration = null, IRepository? repository = null, string? commitId = null, bool onlyTrackedBranches = true, string? targetBranch = null) @@ -173,4 +174,7 @@ private static IServiceProvider ConfigureServices(Action? se servicesOverrides?.Invoke(services); return services.BuildServiceProvider(); } + + private static void DumpGraph(string workingDirectory, Action? writer = null, int? maxCommits = null) + => GitTestExtensions.ExecuteGitCmd(GitExtensions.CreateGitLogArgs(maxCommits), workingDirectory, writer); } diff --git a/src/GitVersion.Core/Core/GitVersionContextFactory.cs b/src/GitVersion.Core/Core/GitVersionContextFactory.cs index b4a17d25d1..d75bc4ab6b 100644 --- a/src/GitVersion.Core/Core/GitVersionContextFactory.cs +++ b/src/GitVersion.Core/Core/GitVersionContextFactory.cs @@ -29,7 +29,8 @@ public GitVersionContext Create(GitVersionOptions gitVersionOptions) currentBranch, gitVersionOptions.RepositoryInfo.CommitId, configuration.Ignore ); - if (currentCommit is null) throw new GitVersionException("No commits found on the current branch."); + if (currentCommit is null) + throw new GitVersionException("No commits found on the current branch."); if (currentBranch.IsDetachedHead) { diff --git a/src/GitVersion.Core/Extensions/GitExtensions.cs b/src/GitVersion.Core/Extensions/GitExtensions.cs index 84f3e74768..104fa9d3ee 100644 --- a/src/GitVersion.Core/Extensions/GitExtensions.cs +++ b/src/GitVersion.Core/Extensions/GitExtensions.cs @@ -1,28 +1,11 @@ -using GitVersion.Helpers; - namespace GitVersion.Extensions; public static class GitExtensions { - public static void DumpGraph(string workingDirectory, Action? writer = null, int? maxCommits = null) + public static void DumpGraphLog(Action? writer = null, int? maxCommits = null) { var output = new StringBuilder(); - try - { - ProcessHelper.Run( - o => output.AppendLine(o), - e => output.AppendLineFormat("ERROR: {0}", e), - null, - "git", - CreateGitLogArgs(maxCommits), - workingDirectory); - } - catch (FileNotFoundException exception) when (exception.FileName == "git") - { - output.AppendLine("Could not execute 'git log' due to the following error:"); - output.AppendLine(exception.ToString()); - } - + output.AppendLine($"Please run `git {CreateGitLogArgs(maxCommits)}` to see the git graph. This can help you troubleshoot any issues."); if (writer != null) { writer(output.ToString()); @@ -36,6 +19,6 @@ public static void DumpGraph(string workingDirectory, Action? writer = n public static string CreateGitLogArgs(int? maxCommits) { var commits = maxCommits != null ? $" -n {maxCommits}" : null; - return $@"log --graph --format=""%h %cr %d"" --decorate --date=relative --all --remotes=*{commits}"; + return $"""log --graph --format="%h %cr %d" --decorate --date=relative --all --remotes=*{commits}"""; } } diff --git a/src/GitVersion.Core/PublicAPI.Shipped.txt b/src/GitVersion.Core/PublicAPI.Shipped.txt index 78e07b591c..e68731b648 100644 --- a/src/GitVersion.Core/PublicAPI.Shipped.txt +++ b/src/GitVersion.Core/PublicAPI.Shipped.txt @@ -753,7 +753,7 @@ static GitVersion.Extensions.EnumerableExtensions.AddRange(this System.Collec static GitVersion.Extensions.EnumerableExtensions.OnlyOrDefault(this System.Collections.Generic.IEnumerable! source) -> T? static GitVersion.Extensions.EnumerableExtensions.SingleOfType(this System.Collections.IEnumerable! source) -> T static GitVersion.Extensions.GitExtensions.CreateGitLogArgs(int? maxCommits) -> string! -static GitVersion.Extensions.GitExtensions.DumpGraph(string! workingDirectory, System.Action? writer = null, int? maxCommits = null) -> void +static GitVersion.Extensions.GitExtensions.DumpGraphLog(System.Action? writer = null, int? maxCommits = null) -> void static GitVersion.Extensions.IncrementStrategyExtensions.ToVersionField(this GitVersion.IncrementStrategy strategy) -> GitVersion.VersionField static GitVersion.Extensions.ReadEmbeddedResourceExtensions.ReadAsStringFromEmbeddedResource(this string! resourceName, System.Reflection.Assembly! assembly) -> string! static GitVersion.Extensions.ReadEmbeddedResourceExtensions.ReadAsStringFromEmbeddedResource(this string! resourceName) -> string! diff --git a/src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs b/src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs index c15937ee55..2da6a5069f 100644 --- a/src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs +++ b/src/GitVersion.Testing/Fixtures/RepositoryFixtureBase.cs @@ -73,7 +73,7 @@ public void Remove(string branch) SequenceDiagram.Destroy(branch); } - public static void Init(string path, string branchName = "main") => GitTestExtensions.ExecuteGitCmd($"init {path} -b {branchName}"); + public static void Init(string path, string branchName = "main") => GitTestExtensions.ExecuteGitCmd($"init {path} -b {branchName}", "."); public string MakeATaggedCommit(string tag) { @@ -165,8 +165,8 @@ protected static Repository CreateNewRepository(string path, string branchName, /// public void MakeShallow() { - GitTestExtensions.ExecuteGitCmd($"-C {RepositoryPath} pull --depth 1"); - GitTestExtensions.ExecuteGitCmd($"-C {RepositoryPath} gc --prune=all"); + GitTestExtensions.ExecuteGitCmd($"-C {RepositoryPath} pull --depth 1", "."); + GitTestExtensions.ExecuteGitCmd($"-C {RepositoryPath} gc --prune=all", "."); } public void Fetch(string remote, FetchOptions? options = null) diff --git a/src/GitVersion.Testing/GitTestExtensions.cs b/src/GitVersion.Testing/GitTestExtensions.cs index ed920fabb0..1c5f1f3420 100644 --- a/src/GitVersion.Testing/GitTestExtensions.cs +++ b/src/GitVersion.Testing/GitTestExtensions.cs @@ -69,7 +69,7 @@ public static Commit CreatePullRequestRef(this IRepository repository, string fr return commit; } - public static void ExecuteGitCmd(string gitCmd, Action? writer = null) + public static void ExecuteGitCmd(string gitCmd, string workingDirectory, Action? writer = null) { var output = new StringBuilder(); try @@ -80,7 +80,7 @@ public static void ExecuteGitCmd(string gitCmd, Action? writer = null) null, "git", gitCmd, - "."); + workingDirectory); } catch (FileNotFoundException exception) when (exception.FileName == "git") { diff --git a/src/GitVersion.Testing/GitVersion.Testing.csproj b/src/GitVersion.Testing/GitVersion.Testing.csproj index 98f9a03956..48fca60324 100644 --- a/src/GitVersion.Testing/GitVersion.Testing.csproj +++ b/src/GitVersion.Testing/GitVersion.Testing.csproj @@ -1,4 +1,4 @@ - + false @@ -7,6 +7,5 @@ - diff --git a/src/GitVersion.Core/Helpers/ProcessHelper.cs b/src/GitVersion.Testing/Helpers/ProcessHelper.cs similarity index 99% rename from src/GitVersion.Core/Helpers/ProcessHelper.cs rename to src/GitVersion.Testing/Helpers/ProcessHelper.cs index 7706fe1324..b5f269ce95 100644 --- a/src/GitVersion.Core/Helpers/ProcessHelper.cs +++ b/src/GitVersion.Testing/Helpers/ProcessHelper.cs @@ -1,9 +1,9 @@ using System.ComponentModel; using System.Runtime.InteropServices; -namespace GitVersion.Helpers; +namespace GitVersion.Testing; -internal static class ProcessHelper +public static class ProcessHelper { private static readonly object LockObject = new(); diff --git a/src/mark-shipped.ps1 b/src/mark-shipped.ps1 old mode 100644 new mode 100755 index df5047a785..45d6270d36 --- a/src/mark-shipped.ps1 +++ b/src/mark-shipped.ps1 @@ -1,3 +1,5 @@ +#! /usr/bin/env pwsh + [CmdletBinding(PositionalBinding = $false)] param () From 70ee4e0b38be487e7b42d70a134fb3a71a34ef11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:19:44 +0000 Subject: [PATCH 4/4] (deps): Bump NUnit.Analyzers Bumps the analyzers group with 1 update in the /src directory: [NUnit.Analyzers](https://github.com/nunit/nunit.analyzers). Updates `NUnit.Analyzers` from 4.2.0 to 4.3.0 - [Release notes](https://github.com/nunit/nunit.analyzers/releases) - [Changelog](https://github.com/nunit/nunit.analyzers/blob/master/CHANGES.md) - [Commits](https://github.com/nunit/nunit.analyzers/compare/4.2.0...4.3.0) --- updated-dependencies: - dependency-name: NUnit.Analyzers dependency-type: direct:production update-type: version-update:semver-minor dependency-group: analyzers ... Signed-off-by: dependabot[bot] --- src/Directory.Packages.props | 2 +- .../Tasks/GenerateGitVersionInformationTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index d733d56241..7ddb66dae2 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -32,7 +32,7 @@ - + diff --git a/src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs b/src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs index cd9a1c7588..a98a3d224e 100644 --- a/src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs +++ b/src/GitVersion.MsBuild.Tests/Tasks/GenerateGitVersionInformationTest.cs @@ -245,7 +245,7 @@ public void GenerateGitVersionInformationTaskShouldCreateFileWhenRunWithMsBuildA result.Output.ShouldContain($"{outputProperty}: {generatedFilePath}"); var fileContent = File.ReadAllText(generatedFilePath); - TestContext.WriteLine(fileContent); + TestContext.Out.WriteLine(fileContent); fileContent.ShouldMatch(string.Format(regexPattern, nameof(GitVersionVariables.Major), "1")); fileContent.ShouldMatch(string.Format(regexPattern, nameof(GitVersionVariables.Minor), "2")); fileContent.ShouldMatch(string.Format(regexPattern, nameof(GitVersionVariables.Patch), "4"));