Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions utilities/pipelines/resourcePublish/Get-ModulesToPublish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,32 @@

<#
.SYNOPSIS
Get modified files between two commits.

.PARAMETER Commit
Optional. A git reference to base the comparison on.

.PARAMETER CompareCommit
Optional. A git reference to compare with.
Get modified files between previous and current commit depending on if you are running on main/master or a custom branch.

.EXAMPLE
Get-ModifiedFileList -Commit "HEAD^" -CompareCommit "HEAD"
Get-ModifiedFileList

Directory: C:\Repo\Azure\ResourceModules\utilities\pipelines\resourcePublish

Mode LastWriteTime Length Name
---- ------------- ------ ----
la--- 08.12.2021 15:50 7133 Script.ps1

Get modified files between previous and current commit.
Get modified files between previous and current commit depending on if you are running on main/master or a custom branch.
#>
function Get-ModifiedFileList {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[string] $Commit = 'HEAD',

[Parameter(Mandatory = $false)]
[string] $CompareCommit = 'HEAD^'
)

Write-Verbose "Gathering modified files between [$CompareCommit] and [$Commit]" -Verbose
$Diff = git diff --name-only --diff-filter=AM $CompareCommit $Commit
$CurrentBranch = Get-GitBranchName
if (($CurrentBranch -eq 'main') -or ($CurrentBranch -eq 'master')) {
Write-Verbose 'Gathering modified files from the pull request' -Verbose
$Diff = git diff --name-only --diff-filter=AM HEAD^ HEAD
} else {
Write-Verbose 'Gathering modified files between current branch and main' -Verbose
$Diff = git diff --name-only --diff-filter=AM origin/main
if ($Diff.count -eq 0) {
Write-Verbose 'Gathering modified files between current branch and master' -Verbose
$Diff = git diff --name-only --diff-filter=AM origin/master
}
}
$ModifiedFiles = $Diff | Get-Item -Force

return $ModifiedFiles
Expand Down