From 1a70ef8f0a2ecb676a7f013d7dc0082adcec5de5 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Mon, 26 Dec 2016 15:16:23 -0300 Subject: [PATCH] Added support for IsDirty flag Fixes #10 and allows conditionals in code that depend on whether the build is clean or dirty from Git's point of view. --- src/GitInfo/build/GitInfo.cs.pp | 4 ++++ src/GitInfo/build/GitInfo.targets | 16 ++++++++++++++++ src/GitInfo/build/GitInfo.vb.pp | 4 ++++ src/GitInfo/readme.txt | 3 +++ 4 files changed, 27 insertions(+) diff --git a/src/GitInfo/build/GitInfo.cs.pp b/src/GitInfo/build/GitInfo.cs.pp index 878d549..cc90e32 100644 --- a/src/GitInfo/build/GitInfo.cs.pp +++ b/src/GitInfo/build/GitInfo.cs.pp @@ -3,6 +3,7 @@ #pragma warning disable 0436 #if ADDMETADATA +[assembly: System.Reflection.AssemblyMetadata("GitInfo.IsDirty", RootNamespace.ThisAssembly.Git.IsDirty)] [assembly: System.Reflection.AssemblyMetadata("GitInfo.Branch", RootNamespace.ThisAssembly.Git.Branch)] [assembly: System.Reflection.AssemblyMetadata("GitInfo.Commit", RootNamespace.ThisAssembly.Git.Commit)] [assembly: System.Reflection.AssemblyMetadata("GitInfo.Sha", RootNamespace.ThisAssembly.Git.Sha)] @@ -30,6 +31,9 @@ /// Provides access to the git information for the current assembly. public partial class Git { + /// IsDirty: $GitIsDirty$ + public const bool IsDirty = $GitIsDirty$; + /// Branch: $GitBranch$ public const string Branch = "$GitBranch$"; diff --git a/src/GitInfo/build/GitInfo.targets b/src/GitInfo/build/GitInfo.targets index da9c725..6697cbe 100644 --- a/src/GitInfo/build/GitInfo.targets +++ b/src/GitInfo/build/GitInfo.targets @@ -185,6 +185,16 @@ + + + @@ -682,6 +692,12 @@ <_ThisAssemblyContent Condition="'$(ThisAssemblyNamespace)' == ''">$(_ThisAssemblyContent.Replace('RootNamespace.', '')) <_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('_RootNamespace_', '$(ThisAssemblyNamespace)')) + + <_ThisAssemblyContent Condition="'$(Language)' == 'C#' And '$(GitIsDirty)' == '1'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'true')) + <_ThisAssemblyContent Condition="'$(Language)' == 'C#' And '$(GitIsDirty)' == '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'false')) + <_ThisAssemblyContent Condition="'$(Language)' == 'VB' And '$(GitIsDirty)' == '1'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'True')) + <_ThisAssemblyContent Condition="'$(Language)' == 'VB' And '$(GitIsDirty)' == '0'">$(_ThisAssemblyContent.Replace('$GitIsDirty$', 'False')) + <_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitBranch$', '$(GitBranch)')) <_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitCommits$', '$(GitCommits)')) <_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitCommit$', '$(GitCommit)')) diff --git a/src/GitInfo/build/GitInfo.vb.pp b/src/GitInfo/build/GitInfo.vb.pp index fe3ec2d..ca58028 100644 --- a/src/GitInfo/build/GitInfo.vb.pp +++ b/src/GitInfo/build/GitInfo.vb.pp @@ -2,6 +2,7 @@ #Const $MetadataDefine$ = 1 #If ADDMETADATA + @@ -28,6 +29,9 @@ Partial Class ThisAssembly ''' Provides access to the git information for the current assembly. Partial Public Class Git + ''' IsDirty: $GitIsDirty$ + Public Const IsDirty = $GitIsDirty$ + ''' Branch: $GitBranch$ Public Const Branch = "$GitBranch$" diff --git a/src/GitInfo/readme.txt b/src/GitInfo/readme.txt index c87843f..a0ddda1 100644 --- a/src/GitInfo/readme.txt +++ b/src/GitInfo/readme.txt @@ -17,6 +17,7 @@ target that depends on the GitInfo target: $(GitSemVerLabel) $(GitSemVerDashLabel) $(GitSemVerSource) + $(GitIsDirty) From C# and VB, by default code is generated too so that the same information can be accessed from code, to construct your own @@ -56,6 +57,8 @@ The available constants from code are: ThisAssembly.Git.SemVer.Label ThisAssembly.Git.SemVer.DashLabel ThisAssembly.Git.SemVer.Source + ThisAssembly.Git.IsDirty + Available MSBuild customizations: