-
Notifications
You must be signed in to change notification settings - Fork 1
/
Restore-Project.ps1
80 lines (69 loc) · 2.02 KB
/
Restore-Project.ps1
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
73
74
75
76
77
78
79
80
param ([Switch]$checkoutHash=$false,[bool]$wait=$True)
# we assume, we start this script in projects "restore" directory
$oldDir = Get-Location
if(-Not (Test-Path -Path platformio.ini))
{
if(Test-Path -Path ../platformio.ini)
{
Set-Location ..
}
}
if(-Not (Test-Path -Path platformio.ini)) {
Write-Host "Skript aus falschem Pfad ausgeführt..."
Write-Host "Entweder aus Root- oder scripts-Ordner"
timeout /T 20
exit 1
}
$projectDir = Get-Location
if(-Not (Test-Path -Path lib/))
{
New-Item -Path $projectDir -Name "lib" -ItemType "directory"
}
$subprojects = Get-Content dependencies.txt
foreach ($subproject in $subprojects) {
$attr = $subproject.Split()
if ($attr[0] -ne "-------") {
Write-Host ""
Write-Host "Subproject $($attr[2])" -ForegroundColor Yellow
if(-Not (Test-Path -Path $attr[2])) {
git clone $attr[3] $attr[2]
if (!$?) {
Write-Host " FAIL: clone" -ForegroundColor Red
Set-Location $oldDir
exit 1
}
}
Set-Location $attr[2]
git fetch --all
if (!$?) {
Write-Host " FAIL: fetch --all" -ForegroundColor Red
Set-Location $oldDir
exit 1
}
if($checkoutHash) {
Write-Host "Checkout Hash $($attr[0])" -ForegroundColor Yellow
git checkout $attr[0]
} else {
Write-Host "Checkout Branch $($attr[1])" -ForegroundColor Yellow
git checkout $attr[1]
}
if (!$?) {
Write-Host " FAIL: checkout" -ForegroundColor Red
Set-Location $oldDir
exit 1
}
if(-Not $checkoutHash) {
git pull --ff-only
if (!$?) {
Write-Host " FAIL: pull --ff-only" -ForegroundColor Red
Set-Location $oldDir
exit 1
}
}
Set-Location $projectDir
}
}
Set-Location $oldDir
if($wait -eq $True) {
timeout /T 20
}