Skip to content

Commit

Permalink
Autodetect is now working and more redundancies have been moved to th…
Browse files Browse the repository at this point in the history
…e shared module
  • Loading branch information
jessehouwing committed Feb 25, 2016
1 parent bed4211 commit 166f3b2
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 42 deletions.
2 changes: 1 addition & 1 deletion extension-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "jessehouwing-vsts-tfvc-tasks-TEST",
"name": "TFVC Build Tasks",
"version": "1.1.19",
"version": "1.1.38",
"publisher": "jessehouwing",
"public": false,
"targets": [
Expand Down
34 changes: 29 additions & 5 deletions vsts-tfvc-add/TfvcAdd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ param(
[string] $ApplyLocalitemExclusions = $true
)

Write-Verbose "Entering script $MyInvocation.MyCommand.Name"
Write-Verbose "Entering script $($MyInvocation.MyCommand.Name)"
Write-Verbose "Parameter Values"
foreach($key in $PSBoundParameters.Keys)
{
Write-Verbose ($key + ' = ' + $PSBoundParameters[$key])
}

Write-Verbose "Importing modules"
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common"
Import-Module -DisableNameChecking "$PSScriptRoot/vsts-tfvc-shared.psm1"

#Backwards compatiblity for the old boolean parameter
Expand All @@ -40,13 +38,39 @@ if ($recursive -ne "")
[string[]] $FilesToAdd = $ItemSpec -split ';|\r?\n'
$RecursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]$Recursion

Write-Output "Adding ItemSpec: $ItemSpec, Recursive: $recursive, Apply Ignorefile: $ApplyLocalitemExclusions"
Write-Output "Adding ItemSpec: $ItemSpec, Recursive: $RecursionType, Apply Ignorefile: $ApplyLocalitemExclusions"

Try
{
$provider = Get-SourceProvider

AutoPend-Workspacechanges -Provider $provider -Items @($FilesToAdd) -RecursionType $RecursionType -ChangeType "Add" -ApplyLocalitemExclusions ($ApplyLocalitemExclusions -eq $true)
if (-not $ApplyLocalitemExclusions)
{
AutoPend-Workspacechanges -Provider $provider -Items @($FilesToAdd) -RecursionType $RecursionType -ChangeType "Add"
}
else
{
if ($RecursionType -eq "OneLevel")
{
Write-Error "RecursionType OneLevel is not supported when ignoring local item exclusions."
return
}

Foreach ($change in $FilesToAdd)
{
Write-Output "Pending Add: $change"

$provider.Workspace.PendAdd(
@($change),
$RecursionType -eq "Full",
$null,
[Microsoft.TeamFoundation.VersionControl.Client.LockLevel]"Unchanged",
$false,
$false,
($ApplyLocalitemExclusions -eq $true)
) | Out-Null
}
}
}
Finally
{
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": 19
"Patch": 38
},
"minimumAgentVersion": "1.83.0",
"groups": [
Expand Down
4 changes: 1 addition & 3 deletions vsts-tfvc-checkin/TfvcCheckin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ param(
[string] $Notes = ""
)

Write-Verbose "Entering script $MyInvocation.MyCommand.Name"
Write-Verbose "Entering script $($MyInvocation.MyCommand.Name)"
Write-Verbose "Parameter Values"
foreach($key in $PSBoundParameters.Keys)
{
Expand All @@ -28,8 +28,6 @@ if (-not ($ConfirmUnderstand -eq $true))
}

Write-Verbose "Importing modules"
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common"
Import-Module -DisableNameChecking "$PSScriptRoot/vsts-tfvc-shared.psm1"

Function Evaluate-Checkin {
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": 19
"Patch": 38
},
"visibility": [
"Build"
Expand Down
12 changes: 7 additions & 5 deletions vsts-tfvc-delete/TfvcDelete.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ param(
[string] $Detect = $true
)

Write-Verbose "Entering script $MyInvocation.MyCommand.Name"
Write-Verbose "Entering script $($MyInvocation.MyCommand.Name)"
Write-Verbose "Parameter Values"
foreach($key in $PSBoundParameters.Keys)
{
Write-Verbose ($key + ' = ' + $PSBoundParameters[$key])
}

Write-Verbose "Importing modules"
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common"
Import-Module -DisableNameChecking "$PSScriptRoot/vsts-tfvc-shared.psm1"

[string[]] $FilesToDelete = $ItemSpec -split ';|\r?\n'
Expand All @@ -32,15 +30,19 @@ Try

if ($Detect -eq $true)
{
Write-Debug "Auto-Detect enabled"
AutoPend-WorkspaceChanges -Provider $provider -Items @($FilesToDelete) -RecursionType $RecursionType -ChangeType "Delete"
}
else
{
Foreach ($delete in $FilesToDelete)
Write-Debug "Auto-Detect disabled"

Foreach ($change in $FilesToDelete)
{
Write-Output "Pending Delete: $change"

$provider.Workspace.PendDelete(
@($delete),
@($change),
$RecursionType,
[Microsoft.TeamFoundation.VersionControl.Client.LockLevel]"Unchanged",
$true,
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": 19
"Patch": 38
},
"minimumAgentVersion": "1.83.0",
"groups": [
Expand Down
73 changes: 48 additions & 25 deletions vsts-tfvc-shared/vsts-tfvc-shared.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function Load-Assembly
{
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common"

function Load-Assembly {
[cmdletbinding()]
param(
[string] $name,
Expand Down Expand Up @@ -108,6 +110,7 @@ function Get-SourceProvider {
[cmdletbinding()]
param()

Write-Debug "Entering Get-SourceProvider"
$provider = @{
Name = $env:BUILD_REPOSITORY_PROVIDER
SourcesRootPath = $env:BUILD_SOURCESDIRECTORY
Expand Down Expand Up @@ -161,6 +164,8 @@ function Get-SourceProvider {
return
}

$provider.Workspace.Refresh()

$success = $true
return New-Object psobject -Property $provider
}
Expand All @@ -170,13 +175,17 @@ function Get-SourceProvider {
if (!$success) {
Invoke-DisposeSourceProvider -Provider $provider
}
Write-Debug "Leaving Get-SourceProvider"
}

}

function Invoke-DisposeSourceProvider {
[cmdletbinding()]
param($Provider)

Write-Debug "Entering Invoke-DisposeSourceProvider"

if ($Provider)
{
if ($Provider.VersionControlServer)
Expand All @@ -190,9 +199,11 @@ function Invoke-DisposeSourceProvider {
$Provider.TfsTeamProjectCollection = $null
}
}

Write-Debug "Leaving Invoke-DisposeSourceProvider"
}

function Detect-WorkspaceChanges{
function Detect-WorkspaceChanges {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)]
Expand All @@ -204,20 +215,28 @@ function Detect-WorkspaceChanges{
[Microsoft.TeamFoundation.VersionControl.Client.ChangeType] $ChangeType
)

$pendingChanges = $null
$ItemSpecs = [Microsoft.TeamFoundation.VersionControl.Client.ItemSpec]::FromStrings(@($Items), $RecursionType)

$provider.Workspace.Refresh()
Write-Debug "Entering Detect-WorkspaceChanges"

$provider.Workspace.GetPendingChangesWithCandidates($ItemSpecs, $false, [ref] $pendingChanges)
try
{
$pendingChanges = $null
$ItemSpecs = [Microsoft.TeamFoundation.VersionControl.Client.ItemSpec]::FromStrings(@($Items), $RecursionType)

return ($pendingChanges |
?{ $_.ChangeType -band $ChangeType } |
Select-Object $_.ServerItem)
$provider.Workspace.GetPendingChangesWithCandidates($ItemSpecs, $false, [ref] $pendingChanges)

$pendingChanges = $pendingChanges | ?{ $_.ChangeType -band $ChangeType }

Write-Debug "Detected Changes of type $($ChangeType): $($pendingChanges.Length)"

return $pendingChanges
}
finally
{
Write-Debug "Leaving Detect-WorkspaceChanges"
}
}

function AutoPend-WorkspaceChanges
{
function AutoPend-WorkspaceChanges {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)]
Expand All @@ -226,25 +245,27 @@ function AutoPend-WorkspaceChanges
[string[]] $Items,
[Parameter(Mandatory=$true)]
[Microsoft.TeamFoundation.VersionControl.Client.RecursionType] $RecursionType,
[Microsoft.TeamFoundation.VersionControl.Client.ChangeType] $ChangeType,
[Parameter(Mandatory=$false)]
[bool] $ApplyLocalItemExclusions = $false
[Microsoft.TeamFoundation.VersionControl.Client.ChangeType] $ChangeType
)

[string[]] $DetectedItems = Detect-WorkspaceChanges -Provider $Provider -Items @($Items) -RecursionType $RecursionType -ChangeType $Changetype
Write-Debug "Entering AutoPend-WorkspaceChanges"

$DetectedItems = Detect-WorkspaceChanges -Provider $Provider -Items @($Items) -RecursionType $RecursionType -ChangeType $Changetype

if ($DetectedItems.Length -eq 0)
if ($DetectedItems -eq $null -or $DetectedItems.Length -eq 0)
{
Write-Output "No changes detected."
return
}

Write-Output "Pending $($ChangeType): $($DetectedItems.ServerItem)"

switch ($ChangeType)
{
"Delete"
{
$provider.Workspace.PendDelete(
@($DetectedItems),
$DetectedItems.ServerItem,
[Microsoft.TeamFoundation.VersionControl.Client.RecursionType]"None",
[Microsoft.TeamFoundation.VersionControl.Client.LockLevel]"Unchanged",
$true,
Expand All @@ -255,13 +276,13 @@ function AutoPend-WorkspaceChanges
"Add"
{
$provider.Workspace.PendAdd(
@($DetectedItems),
$false,
$null,
$DetectedItems.ServerItem,
$false, #recursive
$null,
[Microsoft.TeamFoundation.VersionControl.Client.LockLevel]"Unchanged",
$false,
$false,
$ApplyLocalitemExclusions
$false,
$false, #silent
$true #ApplyLocalItemExclusions, Since GetPendingChangesWithCandidates ignores these anyway.
) | Out-Null
}

Expand All @@ -270,6 +291,8 @@ function AutoPend-WorkspaceChanges
Write-Error "Unsupported auto-pend operation: $ChangeType"
}
}

Write-Debug "Leaving AutoPend-WorkspaceChanges"
}

Export-ModuleMember -Function Invoke-DisposeSourceProvider
Expand Down

0 comments on commit 166f3b2

Please sign in to comment.