...
1# cSpell:ignore Committish
2# cSpell:ignore PULLREQUEST
3# cSpell:ignore TARGETBRANCH
4# cSpell:ignore SOURCECOMMITID
5function Get-ChangedFiles {
6 param (
7 [string]$SourceCommittish= "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}",
8 [string]$TargetCommittish = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/"),
9 [string]$DiffPath,
10 [string]$DiffFilterType = "d"
11 )
12 # If ${env:SYSTEM_PULLREQUEST_TARGETBRANCH} is empty, then return empty.
13 if (!$TargetCommittish -or ($TargetCommittish -eq "origin/")) {
14 Write-Host "There is no target branch passed in. "
15 return ""
16 }
17
18 # Add config to disable the quote and encoding on file name.
19 # Ref: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support#disable-quoted-file-names
20 # Ref: https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support#disable-commit-message-transcoding
21 # Git PR diff: https://docs.github.com/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests#three-dot-and-two-dot-git-diff-comparisons
22 $command = "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff `"$TargetCommittish...$SourceCommittish`" --name-only --diff-filter=$DiffFilterType"
23 if ($DiffPath) {
24 $command = $command + " -- `'$DiffPath`'"
25 }
26 Write-Host $command
27 $changedFiles = Invoke-Expression -Command $command
28 if(!$changedFiles) {
29 Write-Host "No changed files in git diff between $TargetCommittish and $SourceCommittish"
30 }
31 else {
32 Write-Host "Here are the diff files:"
33 foreach ($file in $changedFiles) {
34 Write-Host " $file"
35 }
36 }
37 return $changedFiles
38}
View as plain text