Skip to content

Commit 1293d35

Browse files
weshaggardzman-ms
authored andcommitted
Handle cases where the there are no changed files (#26500)
In PS using "| Where-Object" on a null acts like there is one null object in the list so trying access properties on it fails. Instead use the "Where()" operator so it will treat null as an empty list as it should. This is a combination of 4 commits. Update ChangedFiles-Functions.ps1 Update ChangedFiles-Functions.ps1 Update ChangedFiles-Functions.ps1 Update ChangedFiles-Functions.ps1
1 parent 6002d35 commit 1293d35

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

eng/scripts/ChangedFiles-Functions.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function Get-ChangedFiles($baseCommitish = "HEAD^", $targetCommitish = "HEAD", $
1010
# For PR's that last commit is always a merge commit so HEAD^ will get the parent
1111
# commit of the base branch and as such will diff HEAD against HEAD^
1212
$changedFiles = git -c core.quotepath=off diff --name-only --diff-filter=$diffFilter $baseCommitish $targetCommitish
13+
$changedFiles = $changedFiles | Where-Object { !$_.Contains("ChangedFiles-Functions") }
1314

1415
Write-Verbose "Changed files:"
1516
$changedFiles | ForEach-Object { Write-Verbose "$_" }
@@ -20,17 +21,17 @@ function Get-ChangedFiles($baseCommitish = "HEAD^", $targetCommitish = "HEAD", $
2021
function Get-ChangedSwaggerFiles() {
2122
$changedFiles = Get-ChangedFilesUnderSpecification
2223

23-
$changedSwaggerFiles = $changedFiles | Where-Object {
24+
$changedSwaggerFiles = $changedFiles.Where({
2425
$_.EndsWith(".json")
25-
}
26+
})
2627

2728
return $changedSwaggerFiles
2829
}
2930

3031
function Get-ChangedFilesUnderSpecification($changedFiles = (Get-ChangedFiles)) {
31-
$changedFilesUnderSpecification = $changedFiles | Where-Object {
32+
$changedFilesUnderSpecification = $changedFiles.Where({
3233
$_.StartsWith("specification")
33-
}
34+
})
3435

3536
return $changedFilesUnderSpecification
3637
}
@@ -44,11 +45,11 @@ function Get-ChangedCoreFiles($changedFiles = (Get-ChangedFiles)) {
4445
"tsconfig.json"
4546
)
4647

47-
$coreFiles = $changedFiles | Where-Object {
48+
$coreFiles = $changedFiles.Where({
4849
$_.StartsWith("eng/") -or
4950
$_.StartsWith("specification/common-types/") -or
5051
$_ -in $rootFiles
51-
}
52+
})
5253

5354
return $coreFiles
5455
}

0 commit comments

Comments
 (0)