Skip to content

Commit 4444877

Browse files
Fixed: merging config vs. CLI globbing (#403)
close #402
1 parent 7dbe0f7 commit 4444877

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/Incrementalist.Cmd/Config/ConfigMerger.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// -----------------------------------------------------------------------
66

77
using System;
8+
using System.Linq;
89

910
namespace Incrementalist.Cmd.Config
1011
{
@@ -42,8 +43,8 @@ public static SlnOptions Merge(SlnOptions options, IncrementalistConfig? config)
4243
merged.ContinueOnError = config.ContinueOnError.GetValueOrDefault(true);
4344
merged.RunInParallel = config.RunInParallel.GetValueOrDefault(false);
4445
merged.FailOnNoProjects = config.FailOnNoProjects.GetValueOrDefault(false);
45-
merged.SkipGlobs = options.SkipGlobs ?? config.SkipGlob;
46-
merged.TargetGlobs = options.TargetGlobs ?? config.TargetGlob;
46+
merged.SkipGlobs = MergeGlobs(options.SkipGlobs?.ToArray(), config.SkipGlob);
47+
merged.TargetGlobs = MergeGlobs(options.TargetGlobs?.ToArray(), config.TargetGlob);
4748

4849
// Merge int properties (CLI takes precedence)
4950
merged.TimeoutMinutes = config.TimeoutMinutes.GetValueOrDefault(2);
@@ -62,6 +63,15 @@ public static SlnOptions Merge(SlnOptions options, IncrementalistConfig? config)
6263
return merged;
6364
}
6465

66+
private static string[] MergeGlobs(string[]? primary, string[]? secondary)
67+
{
68+
if(primary is { Length: > 0 })
69+
return primary;
70+
if (secondary is { Length: > 0 })
71+
return secondary;
72+
return [];
73+
}
74+
6575
/// <summary>
6676
/// Apply default values to any null properties.
6777
/// </summary>

src/Incrementalist.Tests/Config/ConfigFileTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ public void Merge_Config_With_CommandLine_Options()
9898
TimeoutMinutes = 5,
9999
Verbose = true,
100100
RunInParallel = true,
101-
OutputFile = "output.txt"
101+
OutputFile = "output.txt",
102+
SkipGlob = ["**/obj/**", "**/bin/**"],
103+
TargetGlob = ["src/**/*.csproj", "tests/**/*.csproj"]
102104
};
103105

104106
var options = new RunOptions()
@@ -123,6 +125,8 @@ public void Merge_Config_With_CommandLine_Options()
123125
Assert.Equal("output.txt", merged.OutputFile); // From config
124126
Assert.True(merged.Verbose); // From config
125127
Assert.True(merged.RunInParallel); // From config
128+
Assert.Equivalent(config.SkipGlob, merged.SkipGlobs); // From config
129+
Assert.Equivalent(config.TargetGlob, merged.TargetGlobs); // From config
126130

127131
// Command-specific options should be preserved
128132
Assert.Equal(3, merged.DotNetArgs.Length);

src/Incrementalist.Tests/Config/SlnOptionsParsingSpecs.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System.Linq;
88
using Incrementalist.Cmd;
9+
using Incrementalist.Cmd.Config;
910
using Microsoft.CodeAnalysis;
1011
using Xunit;
1112
using static Incrementalist.Cmd.SlnOptionsParser;
@@ -34,4 +35,35 @@ public void ShouldSeparateDotnetArgsFromSlnOptions(string cliArg)
3435
Assert.Equal(0, r);
3536
Assert.NotNull(result);
3637
}
38+
39+
/*
40+
* Looking for a suspected bug where:
41+
*
42+
* 1. No globs specified on command line
43+
* 2. globs specified in config file
44+
* 3. Parse operation supplies an empty array instead of a null array
45+
* 4. Merge operation fails because it uses the empty array instead of the config file globs
46+
*/
47+
[Fact]
48+
public void ShouldKeepConfigGlobs()
49+
{
50+
string[] expectedGlobs = ["**/*.Tests.csproj", "**/tests/*.csproj"];
51+
var args = CommandLineParser
52+
.SplitCommandLineIntoArguments("run", true).ToArray();
53+
var r = TryParseSlnOptions(args, out SlnOptions? result);
54+
55+
Assert.Equal(0, r);
56+
Assert.NotNull(result);
57+
58+
var config = new IncrementalistConfig
59+
{
60+
TargetGlob = null,
61+
SkipGlob = expectedGlobs,
62+
GitBranch = "dev",
63+
WorkingDirectory = @"C:\user\workingdir"
64+
};
65+
66+
var merged = ConfigMerger.Merge(result, config);
67+
Assert.Equivalent(expectedGlobs, merged.SkipGlobs);
68+
}
3769
}

0 commit comments

Comments
 (0)