Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce IsDirty boolean property from 2.3 #249

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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