mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-05 12:29:28 +01:00
Update fetch-repos.ps1
This commit is contained in:
parent
b8beb3ef27
commit
48caeda15f
@ -17,33 +17,34 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$ParentDir = "$PWD")
|
param([string]$parentDirPath = "$PWD")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
|
|
||||||
Write-Host "⏳ (1) Searching for Git executable... " -noNewline
|
Write-Host "⏳ (1) Searching for Git executable... " -noNewline
|
||||||
& git --version
|
& git --version
|
||||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||||
|
|
||||||
Write-Host "⏳ (2) Checking parent folder... " -noNewline
|
Write-Host "⏳ (2) Checking parent folder... " -noNewline
|
||||||
if (-not(Test-Path "$ParentDir" -pathType container)) { throw "Can't access folder: $ParentDir" }
|
if (-not(Test-Path "$parentDirPath" -pathType container)) { throw "Can't access folder: $parentDirPath" }
|
||||||
$Folders = (Get-ChildItem "$ParentDir" -attributes Directory)
|
$folders = (Get-ChildItem "$parentDirPath" -attributes Directory)
|
||||||
$NumFolders = $Folders.Count
|
$numFolders = $folders.Count
|
||||||
$ParentDirName = (Get-Item "$ParentDir").Name
|
$parentDirPathName = (Get-Item "$parentDirPath").Name
|
||||||
Write-Host "$NumFolders subfolders"
|
Write-Host "$numFolders subfolders"
|
||||||
|
|
||||||
[int]$Step = 2
|
[int]$step = 3
|
||||||
foreach ($Folder in $Folders) {
|
foreach ($folder in $folders) {
|
||||||
$FolderName = (Get-Item "$Folder").Name
|
$folderName = (Get-Item "$folder").Name
|
||||||
$Step++
|
Write-Host "⏳ ($step/$($numFolders + 2)) Fetching into 📂$folderName... "
|
||||||
Write-Host "⏳ ($Step/$($NumFolders + 2)) Fetching into 📂$FolderName... "
|
|
||||||
|
|
||||||
& git -C "$Folder" fetch --all --recurse-submodules --prune --prune-tags --force
|
& git -C "$folder" fetch --all --recurse-submodules --prune --prune-tags --force
|
||||||
if ($lastExitCode -ne "0") { throw "'git fetch' in $Folder failed with exit code $lastExitCode" }
|
if ($lastExitCode -ne "0") { throw "'git fetch' in $folder failed with exit code $lastExitCode" }
|
||||||
|
|
||||||
|
$step++
|
||||||
}
|
}
|
||||||
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
||||||
"✔️ Fetched updates into 📂$ParentDirName ($NumFolders repos) in $Elapsed sec"
|
"✔️ Fetched updates into $numFolders repos under 📂$parentDirPathName in $elapsed sec"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user