-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPull-Tfs.ps1
More file actions
72 lines (58 loc) · 2.19 KB
/
Pull-Tfs.ps1
File metadata and controls
72 lines (58 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[ValidatePattern("^\d+$")]
[string]$Changeset,
[ValidateScript( {
if (-Not ($_ | Test-Path -PathType Leaf) ) {
throw "The Path argument must be a file. Folder paths are not allowed."
}
return $true
})]
[System.IO.FileInfo] $IgnoreFile,
[Parameter(Mandatory = $true)]
[ValidateScript( {
if ( -Not ($_ | Test-Path) ) {
throw "Folder does not exist"
}
if (-Not ($_ | Test-Path -PathType Container) ) {
throw "The Path argument must be a folder. File paths are not allowed."
}
return $true
})]
[System.IO.FileInfo]$GitRepoDirectory
)
. .\Utils\GitTfs.ps1
# $tfsConfigs = Get-GitTfsConfigs -RepoDirectory $GitRepoDirectory
# if($tfsConfigs.Count -lt 7){
# Write-Error "Failed to fetch from TFS. Reason: The repo '$($GitRepoDirectory.Name)' has not been properly initialized."
# Exit
# }
function Remove-ReadOnlyAttribute ([System.IO.FileInfo] $RepoDirectory) {
Get-ChildItem -Path $RepoDirectory -File -Exclude .\.git -Recurse | ForEach-Object {
$_.IsReadOnly = $false
}
}
Measure-Command {
try {
Write-Host "Pulling from TFS..." -ForegroundColor White
Pull-GitTfs -Changeset $Changeset -IgnoreFile $IgnoreFile -RepoDirectory $GitRepoDirectory | Out-Null
Write-Host "Successfully pulled from TFS." -ForegroundColor Green
Write-Host "Optimizing local Git repo (this may take some time)..." -ForegroundColor White
Run-Optimization -RepoDirectory $GitRepoDirectory | Out-Null
Write-Host "Successfully optimized local Git repo." -ForegroundColor Green
}
catch {
Write-Error "Failed to pull from TFS. Reason: $($_)"
return
}
try {
Write-Host "Removing read-only attribute from files..." -ForegroundColor White
Remove-ReadOnlyAttribute -RepoDirectory $GitRepoDirectory
Write-Host "Successfully removed read-only attributes." -ForegroundColor Green
}
catch {
Write-Error "Failed to remove read-only attribute from files. Reason: $($_)"
return
}
}