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

Add GitCommitDate (#65) #121

Merged
merged 1 commit into from
Sep 11, 2020
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
1 change: 1 addition & 0 deletions src/GitInfo/build/GitInfo.cache.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
GitBranch=$GitBranch$;
GitCommit=$GitCommit$;
GitSha=$GitSha$;
GitCommitDate=$GitCommitDate$;
GitBaseVersion=$GitBaseVersion$;
GitBaseVersionSource=$GitBaseVersionSource$;
GitBaseVersionMajor=$GitBaseVersionMajor$;
Expand Down
4 changes: 4 additions & 0 deletions src/GitInfo/build/GitInfo.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[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)]
[assembly: System.Reflection.AssemblyMetadata("GitInfo.CommitDate", RootNamespace.ThisAssembly.Git.CommitDate)]
[assembly: System.Reflection.AssemblyMetadata("GitInfo.BaseVersion.Major", RootNamespace.ThisAssembly.Git.BaseVersion.Major)]
[assembly: System.Reflection.AssemblyMetadata("GitInfo.BaseVersion.Minor", RootNamespace.ThisAssembly.Git.BaseVersion.Minor)]
[assembly: System.Reflection.AssemblyMetadata("GitInfo.BaseVersion.Patch", RootNamespace.ThisAssembly.Git.BaseVersion.Patch)]
Expand Down Expand Up @@ -51,6 +52,9 @@
/// <summary>Sha: $GitSha$</summary>
public const string Sha = @"$GitSha$";

/// <summary>Commit date: $GitCommitDate$</summary>
public const string CommitDate = @"$GitCommitDate$";

/// <summary>Commits on top of base version: $GitCommits$</summary>
public const string Commits = @"$GitCommits$";

Expand Down
3 changes: 3 additions & 0 deletions src/GitInfo/build/GitInfo.fs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
/// <summary>Sha: $GitSha$</summary>
let [<Literal>] Sha = @"$GitSha$"

/// <summary>Commit date: $GitCommitDate$</summary>
let [<Literal>] CommitDate = @"$GitCommitDate$"

/// <summary>Commits on top of base version: $GitCommits$</summary>
let [<Literal>] Commits = @"$GitCommits$"

Expand Down
31 changes: 31 additions & 0 deletions src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
GitBranch: $(GitBranch)
GitCommit: $(GitCommit)
GitSha: $(GitSha)
GitCommitDate: $(GitCommitDate)
GitBaseVersion: $(GitBaseVersion)
GitBaseVersionSource: $(GitBaseVersionSource)
GitBaseVersionMajor: $(GitBaseVersionMajor)
Expand Down Expand Up @@ -142,17 +143,20 @@
_GitRepositoryUrl;
_GitBranch;
_GitCommit;
_GitCommitDate;
_GitPopulateInfo;
</GitInfoDependsOn>
</PropertyGroup>
<!-- Under Unix, we don't double %% the format. That only works on Windows. -->
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<_ShortShaFormat>%%h</_ShortShaFormat>
<_LongShaFormat>%%H</_LongShaFormat>
<_CommitDateFormat>%%cI</_CommitDateFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<_ShortShaFormat>%h</_ShortShaFormat>
<_LongShaFormat>%H</_LongShaFormat>
<_CommitDateFormat>%cI</_CommitDateFormat>
</PropertyGroup>

<Target Name="GitInfo" DependsOnTargets="$(GitInfoDependsOn)" Returns="@(GitInfo)" />
Expand Down Expand Up @@ -332,6 +336,7 @@
<GitBranch Condition="'$(GitBranch)' == ''">%(GitInfo.GitBranch)</GitBranch>
<GitCommit Condition="'$(GitCommit)' == ''">%(GitInfo.GitCommit)</GitCommit>
<GitSha Condition="'$(GitSha)' == ''">%(GitInfo.GitSha)</GitSha>
<GitCommitDate Condition="'$(GitCommitDate)' == ''">%(GitInfo.GitCommitDate)</GitCommitDate>
<GitBaseVersion Condition="'$(GitBaseVersion)' == ''">%(GitInfo.GitBaseVersion)</GitBaseVersion>
<GitBaseVersionSource Condition="'$(GitBaseVersionSource)' == ''">%(GitInfo.GitBaseVersionSource)</GitBaseVersionSource>
<GitBaseVersionMajor Condition="'$(GitBaseVersionMajor)' == ''">%(GitInfo.GitBaseVersionMajor)</GitBaseVersionMajor>
Expand Down Expand Up @@ -372,6 +377,29 @@
<!--TODO: Sensible default for GitRepositoryUrl-->
</Target>

<Target Name="_GitCommitDate" Returns="$(GitCommitDate)"
DependsOnTargets="_GitRoot"
Inputs="@(_GitInput)"
Outputs="$(_GitInfoFile)"
Condition="'$(GitRoot)' != '' And '$(GitCommitDate)' == ''">

<Exec Command='$(GitExe) show --format=$(_CommitDateFormat) -s'
EchoOff='true'
StandardErrorImportance="low"
StandardOutputImportance="low"
ConsoleToMSBuild="true"
WorkingDirectory="$(GitRoot)"
ContinueOnError="true"
StdOutEncoding='utf-8'>
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommitDate"/>
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>

<PropertyGroup Condition="'$(MSBuildLastExitCode)' != '0'">
<GitCommitDate>0001-01-01T00:00:00+00:00</GitCommitDate>
</PropertyGroup>
</Target>

<Target Name="_GitBranch" Returns="$(GitBranch)"
DependsOnTargets="_GitInputs"
Condition="'$(GitBranch)' == ''"
Expand Down Expand Up @@ -453,6 +481,7 @@
<GitBranch>$(GitBranch)</GitBranch>
<GitCommit>$(GitCommit)</GitCommit>
<GitSha>$(GitSha)</GitSha>
<GitCommitDate>$(GitCommitDate)</GitCommitDate>
</GitInfo>
</ItemGroup>
</Target>
Expand Down Expand Up @@ -839,6 +868,7 @@
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBranch$', '$(GitBranch)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitCommits$', '$(GitCommits)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitCommit$', '$(GitCommit)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitCommitDate$', '$(GitCommitDate)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitSha$', '$(GitSha)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBaseVersion$', '$(GitBaseVersion)'))</_GitInfoContent>
<_GitInfoContent>$(_GitInfoContent.Replace('$GitBaseVersionSource$', '$(GitBaseVersionSource)'))</_GitInfoContent>
Expand Down Expand Up @@ -930,6 +960,7 @@
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitBranch$', '$(GitBranch)'))</_ThisAssemblyContent>
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitCommits$', '$(GitCommits)'))</_ThisAssemblyContent>
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitCommit$', '$(GitCommit)'))</_ThisAssemblyContent>
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitCommitDate$', '$(GitCommitDate)'))</_ThisAssemblyContent>
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitSha$', '$(GitSha)'))</_ThisAssemblyContent>
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitBaseVersion$', '$(GitBaseVersion)'))</_ThisAssemblyContent>
<_ThisAssemblyContent>$(_ThisAssemblyContent.Replace('$GitBaseVersionSource$', '$(GitBaseVersionSource)'))</_ThisAssemblyContent>
Expand Down
4 changes: 4 additions & 0 deletions src/GitInfo/build/GitInfo.vb.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Assembly: System.Reflection.AssemblyMetadata("GitInfo.Branch", Global.RootNamespace.ThisAssembly.Git.Branch)>
<Assembly: System.Reflection.AssemblyMetadata("GitInfo.Commit", Global.RootNamespace.ThisAssembly.Git.Commit)>
<Assembly: System.Reflection.AssemblyMetadata("GitInfo.Sha", Global.RootNamespace.ThisAssembly.Git.Sha)>
<Assembly: System.Reflection.AssemblyMetadata("GitInfo.CommitDate", Global.RootNamespace.ThisAssembly.Git.CommitDate)>
<Assembly: System.Reflection.AssemblyMetadata("GitInfo.BaseVersion.Major", Global.RootNamespace.ThisAssembly.Git.BaseVersion.Major)>
<Assembly: System.Reflection.AssemblyMetadata("GitInfo.BaseVersion.Minor", Global.RootNamespace.ThisAssembly.Git.BaseVersion.Minor)>
<Assembly: System.Reflection.AssemblyMetadata("GitInfo.BaseVersion.Patch", Global.RootNamespace.ThisAssembly.Git.BaseVersion.Patch)>
Expand Down Expand Up @@ -49,6 +50,9 @@
''' <summary>Commit: $GitSha$</summary>
Public Const Sha As String = "$GitSha$"

''' <summary>Commit date: $GitCommitDate$</summary>
Public Const CommitDate As String = "$GitCommitDate$"

''' <summary>Commits on top of base version: $GitCommits$</summary>
Public Const Commits As String = "$GitCommits$"

Expand Down
1 change: 1 addition & 0 deletions src/GitInfo/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target that depends on the GitInfo target:
$(GitRepositoryUrl)
$(GitBranch)
$(GitCommit)
$(GitCommitDate)
$(GitCommits)
$(GitTag)
$(GitBaseTag)
Expand Down