From a79f7585a921bab561e216d767e54822d53c54af Mon Sep 17 00:00:00 2001 From: Jesse Houwing Date: Thu, 25 Feb 2016 19:45:59 +0100 Subject: [PATCH] Fixes a bug where a pended delete is re-detected when auto-pend is turned on for the checkin task. --- extension-manifest.json | 6 +- vsts-tfvc-add/TfvcAdd.ps1 | 5 +- vsts-tfvc-add/task.json | 2 +- vsts-tfvc-checkin/TfvcCheckin.ps1 | 11 ++-- vsts-tfvc-checkin/task.json | 2 +- vsts-tfvc-delete/TfvcDelete.ps1 | 7 +-- vsts-tfvc-delete/task.json | 2 +- vsts-tfvc-shared/vsts-tfvc-shared.psm1 | 77 +++++++++++--------------- 8 files changed, 45 insertions(+), 67 deletions(-) diff --git a/extension-manifest.json b/extension-manifest.json index 76382ca..aaca0dd 100644 --- a/extension-manifest.json +++ b/extension-manifest.json @@ -1,10 +1,10 @@ { "manifestVersion": 1, - "id": "jessehouwing-vsts-tfvc-tasks-TEST", + "id": "jessehouwing-vsts-tfvc-tasks", "name": "TFVC Build Tasks", - "version": "1.1.39", + "version": "1.1.62", "publisher": "jessehouwing", - "public": false, + "public": true, "targets": [ { "id": "Microsoft.VisualStudio.Services" diff --git a/vsts-tfvc-add/TfvcAdd.ps1 b/vsts-tfvc-add/TfvcAdd.ps1 index 246b982..9289c7f 100644 --- a/vsts-tfvc-add/TfvcAdd.ps1 +++ b/vsts-tfvc-add/TfvcAdd.ps1 @@ -12,10 +12,7 @@ param( Write-Verbose "Entering script $($MyInvocation.MyCommand.Name)" Write-Verbose "Parameter Values" -foreach($key in $PSBoundParameters.Keys) -{ - Write-Verbose ($key + ' = ' + $PSBoundParameters[$key]) -} +$PSBoundParameters.Keys | %{ Write-Verbose "$_ = $($PSBoundParameters[$_])" } Write-Verbose "Importing modules" Import-Module -DisableNameChecking "$PSScriptRoot/vsts-tfvc-shared.psm1" diff --git a/vsts-tfvc-add/task.json b/vsts-tfvc-add/task.json index 1192a3e..e207753 100644 --- a/vsts-tfvc-add/task.json +++ b/vsts-tfvc-add/task.json @@ -9,7 +9,7 @@ "version": { "Major": 1, "Minor": 1, - "Patch": 39 + "Patch": 62 }, "minimumAgentVersion": "1.83.0", "groups": [ diff --git a/vsts-tfvc-checkin/TfvcCheckin.ps1 b/vsts-tfvc-checkin/TfvcCheckin.ps1 index 7bb8a11..f8bf766 100644 --- a/vsts-tfvc-checkin/TfvcCheckin.ps1 +++ b/vsts-tfvc-checkin/TfvcCheckin.ps1 @@ -20,19 +20,16 @@ param( Write-Verbose "Entering script $($MyInvocation.MyCommand.Name)" Write-Verbose "Parameter Values" -foreach($key in $PSBoundParameters.Keys) -{ - Write-Verbose ($key + ' = ' + $PSBoundParameters[$key]) -} +$PSBoundParameters.Keys | %{ Write-Verbose "$_ = $($PSBoundParameters[$_])" } + +Write-Verbose "Importing modules" +Import-Module -DisableNameChecking "$PSScriptRoot/vsts-tfvc-shared.psm1" if (-not ($ConfirmUnderstand -eq $true)) { Write-Error "Checking in sources during build can cause delays in your builds, recursive builds, mismatches between sources and symbols and other issues." } -Write-Verbose "Importing modules" -Import-Module -DisableNameChecking "$PSScriptRoot/vsts-tfvc-shared.psm1" - Function Evaluate-Checkin { [cmdletbinding()] param( diff --git a/vsts-tfvc-checkin/task.json b/vsts-tfvc-checkin/task.json index 75239bc..825b50a 100644 --- a/vsts-tfvc-checkin/task.json +++ b/vsts-tfvc-checkin/task.json @@ -9,7 +9,7 @@ "version": { "Major": 1, "Minor": 1, - "Patch": 39 + "Patch": 62 }, "visibility": [ "Build" diff --git a/vsts-tfvc-delete/TfvcDelete.ps1 b/vsts-tfvc-delete/TfvcDelete.ps1 index ca7e771..e4e5d53 100644 --- a/vsts-tfvc-delete/TfvcDelete.ps1 +++ b/vsts-tfvc-delete/TfvcDelete.ps1 @@ -11,10 +11,7 @@ param( Write-Verbose "Entering script $($MyInvocation.MyCommand.Name)" Write-Verbose "Parameter Values" -foreach($key in $PSBoundParameters.Keys) -{ - Write-Verbose ($key + ' = ' + $PSBoundParameters[$key]) -} +$PSBoundParameters.Keys | %{ Write-Verbose "$_ = $($PSBoundParameters[$_])" } Write-Verbose "Importing modules" Import-Module -DisableNameChecking "$PSScriptRoot/vsts-tfvc-shared.psm1" @@ -45,7 +42,7 @@ Try @($change), $RecursionType, [Microsoft.TeamFoundation.VersionControl.Client.LockLevel]"Unchanged", - $true, + $false, $true ) | Out-Null } diff --git a/vsts-tfvc-delete/task.json b/vsts-tfvc-delete/task.json index c7e8cdd..e2343aa 100644 --- a/vsts-tfvc-delete/task.json +++ b/vsts-tfvc-delete/task.json @@ -9,7 +9,7 @@ "version": { "Major": 1, "Minor": 1, - "Patch": 39 + "Patch": 62 }, "minimumAgentVersion": "1.83.0", "groups": [ diff --git a/vsts-tfvc-shared/vsts-tfvc-shared.psm1 b/vsts-tfvc-shared/vsts-tfvc-shared.psm1 index 96bc18f..b7de7e5 100644 --- a/vsts-tfvc-shared/vsts-tfvc-shared.psm1 +++ b/vsts-tfvc-shared/vsts-tfvc-shared.psm1 @@ -5,42 +5,39 @@ function Load-Assembly { [cmdletbinding()] param( [string] $name, - [string[]] $ProbingPathsArgs + [array] $ProbingPaths = @() ) - $ProbingPaths = New-Object System.Collections.ArrayList $ProbingPathsArgs - if ($ProbingPaths.Count -eq 0) + if ($ProbingPaths.Length -eq 0) { Write-Debug "Setting default assembly locations" if ($PSScriptRoot -ne $null ) { - $ProbingPaths.Add($PSScriptRoot) | Out-Null + $ProbingPaths += $PSScriptRoot } if ($env:AGENT_HOMEDIRECTORY -ne $null ) { - $ProbingPaths.Add((Join-Path $env:AGENT_HOMEDIRECTORY "\Agent\Worker\")) | Out-Null + $ProbingPaths += (Join-Path $env:AGENT_HOMEDIRECTORY "\Agent\Worker\") } if ($env:AGENT_SERVEROMDIRECTORY -ne $null) { - $ProbingPaths.Add($env:AGENT_SERVEROMDIRECTORY) | Out-Null + $ProbingPaths += $env:AGENT_SERVEROMDIRECTORY } - $VS1454Path = (Get-ItemProperty -LiteralPath "HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0" -Name 'ShellFolder' -ErrorAction Ignore).ShellFolder + $VS1464Path = (Get-ItemProperty -LiteralPath "HKLM:\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0" -Name 'ShellFolder' -ErrorAction Ignore).ShellFolder if ($VS1464Path -ne $null) { - $ProbingPaths.Add((Join-Path $VS1464Path "\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\")) | Out-Null + $ProbingPaths += (Join-Path $VS1464Path "\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\") } $VS1432Path = (Get-ItemProperty -LiteralPath "HKLM:\SOFTWARE\Microsoft\VisualStudio\14.0" -Name 'ShellFolder' -ErrorAction Ignore).ShellFolder if ($VS1432Path -ne $null) { - $ProbingPaths.Add((Join-Path $VS1432Path "\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\")) | Out-Null + $ProbingPaths += (Join-Path $VS1432Path "\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\") } } - Write-Debug "Resolving $a" - foreach($a in [System.AppDomain]::CurrentDomain.GetAssemblies()) { if ($a.Name -eq $Name) @@ -54,30 +51,19 @@ function Load-Assembly { foreach ($path in $ProbingPaths) { - Write-Debug "Checking in $path" - $path = [System.IO.Path]::Combine($path, "$($assemblyToLoad.Name).dll") - Write-Debug "Looking for $path" if (Test-Path -PathType Leaf -LiteralPath $path) { - Write-Debug "Found assembly: $path" if ([System.Reflection.AssemblyName]::GetAssemblyName($path).Name -eq $assemblyToLoad.Name) { Write-Debug "Loading assembly: $path" - return [System.Reflection.Assembly]::LoadFrom($path) - } - else - { - Write-Debug "Name Mismatch: $path" + $assembly = [System.Reflection.Assembly]::LoadFrom($path) + return; } } - else - { - Write-Debug "Not found: $Name" - } } - return $null + throw "Could not load assembly: $Name" } Load-Assembly "Microsoft.TeamFoundation.Client" @@ -209,7 +195,7 @@ function Detect-WorkspaceChanges { [Parameter(Mandatory=$true)] $Provider, [Parameter(Mandatory=$true)] - [string[]] $Items, + [array] $Items, [Parameter(Mandatory=$true)] [Microsoft.TeamFoundation.VersionControl.Client.RecursionType] $RecursionType, [Microsoft.TeamFoundation.VersionControl.Client.ChangeType] $ChangeType @@ -219,16 +205,16 @@ function Detect-WorkspaceChanges { try { - $pendingChanges = $null - $ItemSpecs = [Microsoft.TeamFoundation.VersionControl.Client.ItemSpec]::FromStrings(@($Items), $RecursionType) - - $provider.Workspace.GetPendingChangesWithCandidates($ItemSpecs, $false, [ref] $pendingChanges) - - $pendingChanges = $pendingChanges | ?{ $_.ChangeType -band $ChangeType } + $AllWorkspaceChanges = @() + $ItemSpecs = @([Microsoft.TeamFoundation.VersionControl.Client.ItemSpec]::FromStrings($Items, $RecursionType)) - Write-Debug "Detected Changes of type $($ChangeType): $($pendingChanges.Length)" + $provider.Workspace.Refresh() + $CurrentPendingChanges = $provider.Workspace.GetPendingChanges([Microsoft.TeamFoundation.VersionControl.Client.ItemSpec[]]$ItemSpecs, $false) + $workspaceChanges = $provider.Workspace.GetPendingChangesWithCandidates($ItemSpecs, $false, [ref] $AllWorkspaceChanges) - return $pendingChanges + $detectedChanges = $AllWorkspaceChanges | Where-Object { $CurrentPendingChanges.ServerItem -notcontains $_.ServerItem } | Where-Object { (($_.ChangeType -band $ChangeType) -eq $ChangeType) -and $_.IsCandidate} + + return $detectedChanges | %{ $_.ServerItem } } finally { @@ -242,7 +228,7 @@ function AutoPend-WorkspaceChanges { [Parameter(Mandatory=$true)] $Provider, [Parameter(Mandatory=$true)] - [string[]] $Items, + [array] $Items, [Parameter(Mandatory=$true)] [Microsoft.TeamFoundation.VersionControl.Client.RecursionType] $RecursionType, [Microsoft.TeamFoundation.VersionControl.Client.ChangeType] $ChangeType @@ -250,40 +236,41 @@ function AutoPend-WorkspaceChanges { Write-Debug "Entering AutoPend-WorkspaceChanges" - $DetectedItems = Detect-WorkspaceChanges -Provider $Provider -Items @($Items) -RecursionType $RecursionType -ChangeType $Changetype - - if ($DetectedItems -eq $null -or $DetectedItems.Length -eq 0) + $DetectedChanges = @(Detect-WorkspaceChanges -Provider $Provider -Items $Items -RecursionType $RecursionType -ChangeType $Changetype) + + if ($DetectedChanges.Length -le 0) { - Write-Output "No changes detected." + Write-Output "No $ChangeType detected." return } - Write-Output "Pending $($ChangeType): $($DetectedItems.ServerItem)" + Write-Output "Pending $($ChangeType): " + $DetectedChanges | %{ Write-output $_ } switch ($ChangeType) { "Delete" { $provider.Workspace.PendDelete( - $DetectedItems.ServerItem, + $DetectedChanges, [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]"None", [Microsoft.TeamFoundation.VersionControl.Client.LockLevel]"Unchanged", $true, $true - ) | Out-Null + ) |Out-Null } "Add" { $provider.Workspace.PendAdd( - $DetectedItems.ServerItem, + $DetectedChanges, $false, #recursive $null, [Microsoft.TeamFoundation.VersionControl.Client.LockLevel]"Unchanged", $false, $false, #silent $true #ApplyLocalItemExclusions, Since GetPendingChangesWithCandidates ignores these anyway. - ) | Out-Null + ) |Out-Null } default @@ -291,7 +278,7 @@ function AutoPend-WorkspaceChanges { Write-Error "Unsupported auto-pend operation: $ChangeType" } } - + Write-Debug "Leaving AutoPend-WorkspaceChanges" }