Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 2824 (#20645)
Browse files Browse the repository at this point in the history
* Common scripts for git diff changes

* Remove the localizer.

* Check not PR triggered case

* Pretty print

Co-authored-by: sima-zhu <sizhu@microsoft.com>
  • Loading branch information
azure-sdk and sima-zhu authored Mar 3, 2022
1 parent 2923269 commit f7a0db1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions eng/common/scripts/git-diff-changes.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f7a0db1

Please sign in to comment.