Skip to content

Commit 6e2383f

Browse files
committed
Ensure IsDirty is a constant
Fixes the regression reported in #287. Fixes #285.
1 parent b0eba91 commit 6e2383f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/Analyzer/GitInfoGenerator.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ class GitInfoGenerator : IIncrementalGenerator
66
public void Initialize(IncrementalGeneratorInitializationContext context)
77
{
88
var ns = context.AnalyzerConfigOptionsProvider
9-
.Select((c, _) => c.GlobalOptions.TryGetValue("build_property.ThisAssemblyNamespace", out var ns)
10-
&& !string.IsNullOrEmpty(ns) ? ns : null);
9+
.Select((c, _) => new
10+
{
11+
Namespace = c.GlobalOptions.TryGetValue("build_property.ThisAssemblyNamespace", out var ns)
12+
&& !string.IsNullOrEmpty(ns) ? ns : null,
13+
IsDirty = c.GlobalOptions.TryGetValue("build_property.GitIsDirty", out var dirty)
14+
&& dirty == "1" ? true : false
15+
});
1116

1217
context.RegisterSourceOutput(ns,
13-
(c, ns) =>
18+
(c, state) =>
1419
{
1520
// Legacy codegen used for this scenario, emit nothing.
16-
if (!string.IsNullOrEmpty(ns))
21+
if (!string.IsNullOrEmpty(state.Namespace))
1722
return;
1823

1924
c.AddSource("ThisAssembly.Git.IsDirty.g",
@@ -36,7 +41,7 @@ partial class Git
3641
/// <summary>
3742
/// Gets whether the current repository is dirty.
3843
/// </summary>
39-
public static bool IsDirty => bool.TryParse(IsDirtyString, out var dirty) && dirty;
44+
public const bool IsDirty = {{(state.IsDirty ? "true" : "false")}};
4045
}
4146
}
4247
""");

src/GitInfo/build/GitInfo.ThisAssembly.targets

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@
3434
</PropertyGroup>
3535

3636
<Target Name="GitThisAssembly" DependsOnTargets="$(GitThisAssemblyDependsOn)"
37-
BeforeTargets="PrepareConstants" Condition="'$(GitThisAssembly)' == 'true'">
37+
BeforeTargets="PrepareConstants;GenerateMSBuildEditorConfigFileShouldRun" Condition="'$(GitThisAssembly)' == 'true'">
3838

3939
<ItemGroup>
40-
<Constant Include="IsDirtyString" Value="$(IsDirtyString)" Root="Git" />
40+
<CompilerVisibleProperty Include="GitIsDirty" />
41+
42+
<Constant Include="IsDirtyString" Value="true" Root="Git" Condition="$(GitIsDirty) == '1'" />
43+
<Constant Include="IsDirtyString" Value="false" Root="Git" Condition="$(GitIsDirty) == '0'" />
44+
4145
<Constant Include="RepositoryUrl" Value="$(GitRepositoryUrl)" Root="Git" />
4246

4347
<Constant Include="Branch" Value="$(GitBranch)" Root="Git" />

0 commit comments

Comments
 (0)