Types/OpenPackage.Part/get_GitDate.ps1

<#
.SYNOPSIS
    Gets Package Part Git Dates
.DESCRIPTION
    Gets any Git commit Dates associated with a package part.

    This must be run from within a git repository,
    and the part source file must exist in the repository.
.NOTES
    The package must have two relationships for this to work:

    1. A `git` `repository`, to indicate the git repository
    2. A `source` `directory`, to indicate the source directory.
#>


if (-not $this.Package.RelationshipExists) { return }
$repoExists = $this.Package.RelationshipExists('repository')
if (-not $repoExists) { return }

$sourceExists = $this.Package.RelationshipExists('directory')
if (-not $sourceExists) { return }

$gitApp = $executionContext.SessionState.InvokeCommand.GetCommand('git', 'application')

if (-not $gitApp) { return }

$gitRoot = try { & $gitApp rev-parse --show-toplevel *&>1} catch {$LASTEXITCODE = 0} 

$directory = Get-Item -LiteralPath $gitRoot -ErrorAction Ignore
if (-not $directory) { return }

$filePath = Join-Path $directory $this.Uri
$file = Get-Item -LiteralPath $filePath -ErrorAction Ignore

if (-not $file) { return }

@(& $gitApp log --follow --format=%ci --date default $file.FullName *>&1) -as [datetime[]]