Sync eng/common directory with azure-sdk-tools for PR 2824 (#3389)
* Common scripts for git diff changes * Remove the localizer. * Check not PR triggered case * Pretty print Co-authored-by: sima-zhu <sizhu@microsoft.com>
This commit is contained in:
parent
f3c3d5fa0b
commit
cd2e916296
36
eng/common/scripts/git-diff-changes.ps1
Normal file
36
eng/common/scripts/git-diff-changes.ps1
Normal file
@ -0,0 +1,36 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Returns git diff changes in pull request.
|
||||
|
||||
.DESCRIPTION
|
||||
The script is to return diff changes in pull request.
|
||||
|
||||
.PARAMETER SourceCommittish
|
||||
The branch committish PR merges from.
|
||||
Definition of committish: https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefcommit-ishacommit-ishalsocommittish
|
||||
|
||||
.PARAMETER TargetCommittish
|
||||
The branch committish PR targets to merge into.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[string] $SourceCommittish = "${env:BUILD_SOURCEVERSION}",
|
||||
[string] $TargetCommittish = ("origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" -replace "refs/heads/")
|
||||
)
|
||||
|
||||
# If ${env:SYSTEM_PULLREQUEST_TARGETBRANCH} is empty, then return empty.
|
||||
if ($TargetCommittish -eq "origin/") {
|
||||
Write-Host "There is no target branch passed in. "
|
||||
return ""
|
||||
}
|
||||
# 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
|
||||
Write-Host "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff $TargetCommittish...$SourceCommittish --name-only --diff-filter=d"
|
||||
$changedFiles = (git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff "$TargetCommittish...$SourceCommittish" --name-only --diff-filter=d)
|
||||
if(!$changedFiles) {
|
||||
Write-Host "No changed files in git diff between $TargetCommittish and $SourceCommittish"
|
||||
}
|
||||
Write-Host "Here are the diff files:"
|
||||
foreach ($file in $changedFiles) {
|
||||
Write-Host " $file"
|
||||
}
|
||||
return $changedFiles
|
||||
Loading…
Reference in New Issue
Block a user