diff --git a/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml b/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml index 6857710ec..ff4927b8b 100644 --- a/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml +++ b/eng/common/pipelines/templates/steps/eng-common-workflow-enforcer.yml @@ -8,11 +8,10 @@ steps: - pwsh: | # Find the default branch of the repo. The variable value sets in build step. Write-Host "Default Branch: $(DefaultBranch)" - $targetBranch = "$(System.PullRequest.TargetBranch)" -replace "refs/heads/" - if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and $targetBranch -eq "$(DefaultBranch)") + if ((!"$(System.PullRequest.SourceBranch)".StartsWith("sync-eng/common")) -and "$(System.PullRequest.TargetBranch)" -match "^(refs/heads/)?$(DefaultBranch)$") { - $filesInCommonDir = & "eng/common/scripts/get-changedfiles.ps1" -TargetCommittish $targetBranch -DiffPath 'eng/common/*' + $filesInCommonDir = & "eng/common/scripts/get-changedfiles.ps1" -DiffPath 'eng/common/*' if (($LASTEXITCODE -eq 0) -and ($filesInCommonDir.Count -gt 0)) { Write-Host "##vso[task.LogIssue type=error;]Changes to files under 'eng/common' directory should not be made in this Repo`n${filesInCommonDir}" diff --git a/eng/common/scripts/Helpers/git-helpers.ps1 b/eng/common/scripts/Helpers/git-helpers.ps1 index 8c72542a0..e9feafe46 100644 --- a/eng/common/scripts/Helpers/git-helpers.ps1 +++ b/eng/common/scripts/Helpers/git-helpers.ps1 @@ -10,7 +10,7 @@ function Get-ChangedFiles { [string]$DiffFilterType = "d" ) # If ${env:SYSTEM_PULLREQUEST_TARGETBRANCH} is empty, then return empty. - if ($TargetCommittish -eq "origin/") { + if (!$TargetCommittish -or ($TargetCommittish -eq "origin/")) { Write-Host "There is no target branch passed in. " return "" }