Skip to content

Commit

Permalink
Reintroduce IsDirty boolean property from 2.3
Browse files Browse the repository at this point in the history
With the change to ThisAssembly.Constants, we introduced a bug that caused IsDirty to be a string contant, instead of the boolean it was up to 2.3.

Closes #243
  • Loading branch information
kzu committed Feb 22, 2023
1 parent 3357655 commit f9408fe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/Analyzer/GitInfoGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.CodeAnalysis;

[Generator(LanguageNames.CSharp)]
class GitInfoGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterSourceOutput(
context.AdditionalTextsProvider
.Combine(context.AnalyzerConfigOptionsProvider)
.Combine(context.ParseOptionsProvider)
.Collect(),
(c, _) =>
{
c.AddSource("ThisAssembly.Git.IsDirty.g",
$$"""
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// GitInfo: {{ThisAssembly.Info.InformationalVersion}}
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
partial class ThisAssembly
{
partial class Git
{
/// <summary>
/// Gets whether the current repository is dirty.
/// </summary>
public static bool IsDirty => bool.TryParse(IsDirtyString, out var dirty) && dirty;
}
}
""");
});
}
}
1 change: 0 additions & 1 deletion src/GitInfo/build/GitInfo.ThisAssembly.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
BeforeTargets="PrepareConstants" Condition="'$(GitThisAssembly)' == 'true'">

<ItemGroup>
<Constant Include="IsDirty" Value="$(IsDirty)" Root="Git" />
<Constant Include="IsDirtyString" Value="$(IsDirtyString)" Root="Git" />
<Constant Include="RepositoryUrl" Value="$(GitRepositoryUrl)" Root="Git" />

Expand Down

0 comments on commit f9408fe

Please sign in to comment.