Skip to content

Commit

Permalink
Merge pull request #333 from rkeithhill/rkeithhill/fix-v2-issues-with…
Browse files Browse the repository at this point in the history
…-PR319

Fix PR 319 to work on PS v2/v3.
  • Loading branch information
rkeithhill authored Dec 30, 2016
2 parents 50ba16a + 582651d commit 3299116
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,33 @@ function Get-GitStatus($gitDir = (Get-GitDirectory)) {

$indexPaths = @(GetUniquePaths $indexAdded,$indexModified,$indexDeleted,$indexUnmerged)
$workingPaths = @(GetUniquePaths $filesAdded,$filesModified,$filesDeleted,$filesUnmerged)
$index = Write-Output -NoEnumerate $indexPaths |
Add-Member -PassThru NoteProperty Added $indexAdded.ToArray() |
Add-Member -PassThru NoteProperty Modified $indexModified.ToArray() |
Add-Member -PassThru NoteProperty Deleted $indexDeleted.ToArray() |
Add-Member -PassThru NoteProperty Unmerged $indexUnmerged.ToArray()

$working = Write-Output -NoEnumerate $workingPaths|
Add-Member -PassThru NoteProperty Added $filesAdded |
Add-Member -PassThru NoteProperty Modified $filesModified.ToArray() |
Add-Member -PassThru NoteProperty Deleted $filesDeleted.ToArray() |
Add-Member -PassThru NoteProperty Unmerged $filesUnmerged.ToArray()

# PowerShell v2 and v3 Write-Output doesn't have a NoEnumerate parameter
if ($PSVersionTable.PSVersion.Major -le 3) {
$index = New-Object PSObject @(,@($indexPaths | Where-Object { $_ })) |
Add-Member -PassThru NoteProperty Added $indexAdded |
Add-Member -PassThru NoteProperty Modified $indexModified |
Add-Member -PassThru NoteProperty Deleted $indexDeleted |
Add-Member -PassThru NoteProperty Unmerged $indexUnmerged
$working = New-Object PSObject @(,@($workingPaths | Where-Object { $_ })) |
Add-Member -PassThru NoteProperty Added $filesAdded |
Add-Member -PassThru NoteProperty Modified $filesModified |
Add-Member -PassThru NoteProperty Deleted $filesDeleted |
Add-Member -PassThru NoteProperty Unmerged $filesUnmerged
}
else {
$index = Write-Output -NoEnumerate $indexPaths |
Add-Member -PassThru NoteProperty Added $indexAdded.ToArray() |
Add-Member -PassThru NoteProperty Modified $indexModified.ToArray() |
Add-Member -PassThru NoteProperty Deleted $indexDeleted.ToArray() |
Add-Member -PassThru NoteProperty Unmerged $indexUnmerged.ToArray()

$working = Write-Output -NoEnumerate $workingPaths|
Add-Member -PassThru NoteProperty Added $filesAdded |
Add-Member -PassThru NoteProperty Modified $filesModified.ToArray() |
Add-Member -PassThru NoteProperty Deleted $filesDeleted.ToArray() |
Add-Member -PassThru NoteProperty Unmerged $filesUnmerged.ToArray()
}

$result = New-Object PSObject -Property @{
GitDir = $gitDir
Expand Down

0 comments on commit 3299116

Please sign in to comment.