From 178b1d370de3ad4f04835692ac27674819f7a358 Mon Sep 17 00:00:00 2001 From: "david@DAVID-PC" <3200210+davidjenni@users.noreply.github.com> Date: Tue, 25 Nov 2025 14:30:22 -0800 Subject: [PATCH 1/2] fix: /diag behaves like a proper boolean switch before fix, order of arguments mattered: - unless /diag is last argument, it is ignored; and the following argument is swalloed silently /diag /l gv.log -> diagnostic switch is ignored, no log file is created /l console /diag -> diagnostic output is emitted to console /l gv.log /diag -> diagnostic output is emitted to log file --- src/GitVersion.App/ArgumentParser.cs | 6 +----- src/GitVersion.App/ArgumentParserExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/GitVersion.App/ArgumentParser.cs b/src/GitVersion.App/ArgumentParser.cs index 1f85a1b3d2..d7b4df31bc 100644 --- a/src/GitVersion.App/ArgumentParser.cs +++ b/src/GitVersion.App/ArgumentParser.cs @@ -212,11 +212,7 @@ private static bool ParseSwitches(Arguments arguments, string? name, IReadOnlyLi if (name.IsSwitch("diag")) { - if (value?.IsTrue() != false) - { - arguments.Diag = true; - } - + arguments.Diag = true; return true; } diff --git a/src/GitVersion.App/ArgumentParserExtensions.cs b/src/GitVersion.App/ArgumentParserExtensions.cs index 7d0dade040..286849c44b 100644 --- a/src/GitVersion.App/ArgumentParserExtensions.cs +++ b/src/GitVersion.App/ArgumentParserExtensions.cs @@ -73,7 +73,7 @@ public bool IsSwitch(string switchName) public bool ArgumentRequiresValue(int argumentIndex) { - var booleanArguments = new[] { "updateassemblyinfo", "ensureassemblyinfo", "nofetch", "nonormalize", "nocache", "allowshallow" }; + var booleanArguments = new[] { "updateassemblyinfo", "ensureassemblyinfo", "nofetch", "nonormalize", "nocache", "allowshallow", "diag" }; var argumentMightRequireValue = !booleanArguments.Contains(singleArgument[1..], StringComparer.OrdinalIgnoreCase); From 0b5484647c12494e690278d71115b2241482b0cc Mon Sep 17 00:00:00 2001 From: "david@DAVID-PC" <3200210+davidjenni@users.noreply.github.com> Date: Tue, 25 Nov 2025 14:50:20 -0800 Subject: [PATCH 2/2] test: -diag switch order in arg list doesn't matter --- src/GitVersion.App.Tests/ArgumentParserTests.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/GitVersion.App.Tests/ArgumentParserTests.cs b/src/GitVersion.App.Tests/ArgumentParserTests.cs index 42e7c36304..911c1f0812 100644 --- a/src/GitVersion.App.Tests/ArgumentParserTests.cs +++ b/src/GitVersion.App.Tests/ArgumentParserTests.cs @@ -636,6 +636,21 @@ public void AllowshallowTrueWhenDefined() arguments.AllowShallow.ShouldBe(true); } + [Test] + public void DiagTrueWhenDefined() + { + var arguments = this.argumentParser.ParseArguments("-diag"); + arguments.Diag.ShouldBe(true); + } + + [Test] + public void DiagAndLogToConsoleIsNotIgnored() + { + var arguments = this.argumentParser.ParseArguments("-diag -l console"); + arguments.Diag.ShouldBe(true); + arguments.LogFilePath.ShouldBe("console"); + } + [Test] public void OtherArgumentsCanBeParsedBeforeNofetch() {