Skip to content
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
29 changes: 29 additions & 0 deletions .build/BuildFunctions/Get-FileMostRecentCommit.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

. $PSScriptRoot\Test-PathCaseSensitive.ps1

function Get-FileMostRecentCommit {
[CmdletBinding()]
[OutputType([DateTime])]
param (
[Parameter()]
[string]
$File
)

Write-Verbose "Get-FileMostRecentCommit called for file $File"

if (-not (Test-PathCaseSensitive $File)) {
Write-Error "Path case is not correct: $File"
}

try {
$commitTime = [DateTime]::Parse((git log -n 1 --format="%ad" --date=rfc $File))
Write-Verbose "Commit time $commitTime for file $File"
return $commitTime
} catch {
Write-Error "Failed to get commit time for file $File"
throw
}
}
17 changes: 8 additions & 9 deletions .build/BuildFunctions/Get-ScriptProjectMostRecentCommit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT License.

. $PSScriptRoot\Get-EmbeddedFileList.ps1
. $PSScriptRoot\Get-FileMostRecentCommit.ps1

<#
.SYNOPSIS
Expand All @@ -19,15 +20,13 @@ function Get-ScriptProjectMostRecentCommit {

process {
Write-Verbose "Get-ScriptProjectMostRecentCommit called for file $File"
$mostRecentCommit = [DateTime]::MinValue
if ([DateTime]::TryParse((git log -n 1 --format="%ad" --date=rfc $File), [ref] $mostRecentCommit)) {
Get-EmbeddedFileList $File | ForEach-Object {
Write-Verbose "Getting commit time for $_"
$commitTime = [DateTime]::Parse((git log -n 1 --format="%ad" --date=rfc $_))
if ($commitTime -gt $mostRecentCommit) {
$mostRecentCommit = $commitTime
Write-Host ("Changing commit time to: $($commitTime.ToString("yy.MM.dd.HHmm"))")
}
$mostRecentCommit = Get-FileMostRecentCommit $File
foreach ($embeddedFile in (Get-EmbeddedFileList $File)) {
Write-Verbose "Getting commit time for $embeddedFile"
$commitTime = Get-FileMostRecentCommit $embeddedFile
if ($commitTime -gt $mostRecentCommit) {
$mostRecentCommit = $commitTime
Write-Host ("Changing commit time to: $($commitTime.ToString("yy.MM.dd.HHmm"))")
}
}

Expand Down
29 changes: 29 additions & 0 deletions .build/BuildFunctions/Test-PathCaseSensitive.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

function Test-PathCaseSensitive {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Path
)

if (-not (Test-Path $Path)) {
Write-Warning "Path does not exist: $Path"
return $false
}

$directoryName = [IO.Path]::GetDirectoryName($Path)
$fileName = [IO.Path]::GetFileName($Path)
$childItem = Get-ChildItem $directoryName -Filter $fileName
$actualPath = $childItem.FullName
if ($actualPath -ceq $Path) {
return $true
}

Write-Warning "Provided path: $Path"
Write-Warning "Actual path: $actualPath"
Write-Warning "Path case is not correct."
return $false
}