-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCleanRepoGroup_DirectoryAll_TEMPLATE.ps1
More file actions
57 lines (46 loc) · 1.63 KB
/
CleanRepoGroup_DirectoryAll_TEMPLATE.ps1
File metadata and controls
57 lines (46 loc) · 1.63 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
# Git-Cleans all repository clones in this directory.
Write-Host "`n`nGit-cleaning all repository clones in directory XXYY/ ...`n"
# Get the script directory such that relative paths can be resolved:
$scriptPath = $MyInvocation.MyCommand.Path
$scriptDir = Split-Path $scriptPath -Parent
# $scriptFilename = [System.IO.Path]::GetFileName($scriptPath)
Write-Host "Script directory: $scriptDir"
function Write-Warn {
param([string]$Message)
Write-Host "Warning: $Message" -ForegroundColor Yellow
}
function CleanRepository {
param([string]$Directory)
$currentDirSaved = $(Get-Location)
try {
if (-Not (Test-Path -Path $Directory)) {
Write-Warn "CleanRepository: Directory doesn't exist:`n $Directory"
return
}
# Write-Host "`nExecuting CleanRepository $Directory ..."
# Write-Host "Current dir: $currentDirSaved"
Set-Location -Path "$Directory"
# Write-Host "Current dir after change: $(Get-Location)"
# Write-Host cleaning git repo...
git clean -f -x -d
}
catch {
Write-Warn " WARNING: Error occurred when executing CleanRepository."
}
finally {
Set-Location -Path "$currentDirSaved"
# Write-Host "Current dir after changing back: $(Get-Location)"
# Write-Host "CleanRepository completed.`n"
}
}
# Write-Host "`nGit-cleaning repository basic directories:"
# & $(Join-Path $scriptDir "CleanRepoGroup_DirectoryBasic.ps1")
Write-Host "`nGit-cleaning repository '' ..."
try {
& CleanRepository $(Join-Path $scriptDir "")
}
catch {
Write-Warn " Directory does not exist, or error occurred."
}
Write-Host " ... cleaning directory completed."
Write-Host "`n... cleaning repositories in XXYY/ completed.`n`n"