Skip to content

Commit

Permalink
Fixes a bug where a pended delete is re-detected when auto-pend is tu…
Browse files Browse the repository at this point in the history
…rned on for the checkin task.
  • Loading branch information
jessehouwing committed Feb 25, 2016
1 parent 5d6402c commit a79f758
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 67 deletions.
6 changes: 3 additions & 3 deletions extension-manifest.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 1 addition & 4 deletions vsts-tfvc-add/TfvcAdd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion vsts-tfvc-add/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": {
"Major": 1,
"Minor": 1,
"Patch": 39
"Patch": 62
},
"minimumAgentVersion": "1.83.0",
"groups": [
Expand Down
11 changes: 4 additions & 7 deletions vsts-tfvc-checkin/TfvcCheckin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion vsts-tfvc-checkin/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": {
"Major": 1,
"Minor": 1,
"Patch": 39
"Patch": 62
},
"visibility": [
"Build"
Expand Down
7 changes: 2 additions & 5 deletions vsts-tfvc-delete/TfvcDelete.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -45,7 +42,7 @@ Try
@($change),
$RecursionType,
[Microsoft.TeamFoundation.VersionControl.Client.LockLevel]"Unchanged",
$true,
$false,
$true
) | Out-Null
}
Expand Down
2 changes: 1 addition & 1 deletion vsts-tfvc-delete/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"version": {
"Major": 1,
"Minor": 1,
"Patch": 39
"Patch": 62
},
"minimumAgentVersion": "1.83.0",
"groups": [
Expand Down
77 changes: 32 additions & 45 deletions vsts-tfvc-shared/vsts-tfvc-shared.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -242,56 +228,57 @@ 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
)

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
{
Write-Error "Unsupported auto-pend operation: $ChangeType"
}
}

Write-Debug "Leaving AutoPend-WorkspaceChanges"
}

Expand Down

0 comments on commit a79f758

Please sign in to comment.