Skip to content

Commit 26d1fa8

Browse files
committed
Fix whitespace tooling edge cases
1 parent b6ac397 commit 26d1fa8

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
#!/usr/bin/env pwsh
22
$ErrorActionPreference = 'Continue'
33

4+
if (Test-Path -LiteralPath 'check-results.log') {
5+
Remove-Item -LiteralPath 'check-results.log' -Force
6+
}
7+
48
& "$PSScriptRoot/check-whitespace.ps1"
59
$ec = $LASTEXITCODE
610

7-
& "$PSScriptRoot/fix-whitespace.ps1"
11+
if ($ec -eq 0 -or (Test-Path -LiteralPath 'check-results.log')) {
12+
& "$PSScriptRoot/fix-whitespace.ps1"
13+
}
14+
else {
15+
Write-Error 'Whitespace checker failed before producing results; skipping fixer.'
16+
}
817

918
exit $ec

Build/Agent/check-whitespace.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Write-Host "Base ref: $baseRef ($baseSha)"
3838
$log = git log --check --pretty=format:'---% h% s' "$baseSha.." 2>&1
3939
$null = $log | Tee-Object -FilePath check-results.log
4040
$log | Out-Host
41+
if (-not (Test-Path -LiteralPath 'check-results.log')) {
42+
New-Item -ItemType File -Path 'check-results.log' -Force | Out-Null
43+
}
4144

4245
$problems = New-Object System.Collections.Generic.List[string]
4346
$commit = ''
@@ -46,7 +49,7 @@ $commitTextmd = ''
4649
$repoPath = Get-RepoPath
4750
$headRef = (git rev-parse --abbrev-ref HEAD 2>$null)
4851

49-
Get-Content check-results.log | ForEach-Object {
52+
$log | ForEach-Object {
5053
$line = $_
5154
switch -regex ($line) {
5255
'^---\s' {
@@ -83,7 +86,7 @@ Get-Content check-results.log | ForEach-Object {
8386
}
8487

8588
if ($problems.Count -gt 0) {
86-
Write-Host "`u26A0`uFE0F Please review the output for further information."
89+
Write-Host '[WARN] Please review the output for further information.'
8790
Write-Host '### A whitespace issue was found in one or more of the commits.'
8891
Write-Host 'This check validates commit history from origin/main..HEAD, not just the current working tree.'
8992
Write-Host 'If the report names an older commit, fix the file and then amend, squash, or rebase so that commit no longer appears in the branch history.'

Build/Agent/fix-whitespace.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if (Test-Path -LiteralPath 'check-results.log') {
7878
if (-not $fixFiles -or $fixFiles.Count -eq 0) {
7979
$base = Get-BaseRef
8080
Write-Host "Fixing whitespace for files changed since $base..HEAD"
81-
$fixFiles = git diff --name-only "$base"..HEAD
81+
$fixFiles = git diff --name-only $base HEAD
8282
}
8383

8484
$files = $fixFiles | Where-Object { $_ -and (Test-Path $_) }

0 commit comments

Comments
 (0)