diff --git a/.build/BuildFunctions/Get-FileMostRecentCommit.ps1 b/.build/BuildFunctions/Get-FileMostRecentCommit.ps1 new file mode 100644 index 0000000000..be8fe50035 --- /dev/null +++ b/.build/BuildFunctions/Get-FileMostRecentCommit.ps1 @@ -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 + } +} diff --git a/.build/BuildFunctions/Get-ScriptProjectMostRecentCommit.ps1 b/.build/BuildFunctions/Get-ScriptProjectMostRecentCommit.ps1 index 8ecf0ffcd0..2aa2e743e1 100644 --- a/.build/BuildFunctions/Get-ScriptProjectMostRecentCommit.ps1 +++ b/.build/BuildFunctions/Get-ScriptProjectMostRecentCommit.ps1 @@ -2,6 +2,7 @@ # Licensed under the MIT License. . $PSScriptRoot\Get-EmbeddedFileList.ps1 +. $PSScriptRoot\Get-FileMostRecentCommit.ps1 <# .SYNOPSIS @@ -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"))") } } diff --git a/.build/BuildFunctions/Test-PathCaseSensitive.ps1 b/.build/BuildFunctions/Test-PathCaseSensitive.ps1 new file mode 100644 index 0000000000..c9dc3e7abb --- /dev/null +++ b/.build/BuildFunctions/Test-PathCaseSensitive.ps1 @@ -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 +}