2023-10-31 11:25:11 +01:00
|
|
|
<#
|
2021-09-29 08:28:20 +02:00
|
|
|
.SYNOPSIS
|
2023-08-04 12:04:09 +02:00
|
|
|
Pulls updates into Git repos
|
2021-07-13 21:10:02 +02:00
|
|
|
.DESCRIPTION
|
2023-08-04 12:04:09 +02:00
|
|
|
This PowerShell script pulls updates into all Git repositories in a folder (including submodules).
|
2023-10-15 10:09:16 +02:00
|
|
|
.PARAMETER parentDir
|
2021-10-16 16:50:10 +02:00
|
|
|
Specifies the path to the parent folder
|
2021-07-13 21:10:02 +02:00
|
|
|
.EXAMPLE
|
2021-09-24 17:19:49 +02:00
|
|
|
PS> ./pull-repos C:\MyRepos
|
2023-10-15 10:09:16 +02:00
|
|
|
⏳ (1) Searching for Git executable... git version 2.42.0
|
|
|
|
⏳ (2) Checking parent folder... 33 subfolders
|
2023-08-03 07:35:51 +02:00
|
|
|
⏳ (3/35) Pulling into 📂base256unicode...
|
|
|
|
...
|
2021-07-13 21:10:02 +02:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-04-14 07:39:34 +02:00
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-01-20 16:11:38 +01:00
|
|
|
#>
|
|
|
|
|
2023-10-15 10:09:16 +02:00
|
|
|
param([string]$parentDir = "$PWD")
|
2021-02-18 20:17:55 +01:00
|
|
|
|
2021-02-13 10:26:14 +01:00
|
|
|
try {
|
2023-10-15 10:09:16 +02:00
|
|
|
$stopWatch = [system.diagnostics.stopwatch]::startNew()
|
2021-03-19 17:43:28 +01:00
|
|
|
|
2023-10-15 10:09:16 +02:00
|
|
|
Write-Host "⏳ (1) Searching for Git executable...`t`t" -NoNewline
|
2022-08-06 14:25:55 +02:00
|
|
|
& git --version
|
2021-03-20 14:36:45 +01:00
|
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
|
|
|
|
2023-10-15 10:09:16 +02:00
|
|
|
Write-Host "⏳ (2) Checking parent folder...`t`t" -NoNewline
|
|
|
|
if (-not(Test-Path "$parentDir" -pathType container)) { throw "Can't access folder: $parentDir" }
|
|
|
|
$folders = (Get-ChildItem "$parentDir" -attributes Directory)
|
|
|
|
$numFolders = $folders.Count
|
|
|
|
$parentDirName = (Get-Item "$parentDir").Name
|
|
|
|
Write-Host "$numFolders subfolders"
|
2021-02-28 18:49:53 +01:00
|
|
|
|
2023-10-15 10:09:16 +02:00
|
|
|
[int]$step = 3
|
|
|
|
[int]$failed = 0
|
|
|
|
foreach ($folder in $folders) {
|
|
|
|
$folderName = (Get-Item "$folder").Name
|
|
|
|
Write-Host "⏳ ($step/$($numFolders + 2)) Pulling into 📂$folderName...`t`t" -NoNewline
|
2021-02-28 18:49:53 +01:00
|
|
|
|
2023-10-15 10:09:16 +02:00
|
|
|
& git -C "$folder" pull --recurse-submodules --jobs=4
|
|
|
|
if ($lastExitCode -ne "0") { $failed++; write-warning "'git pull' in 📂$folderName failed" }
|
2021-06-16 08:38:33 +02:00
|
|
|
|
2023-10-15 10:09:16 +02:00
|
|
|
& git -C "$folder" submodule update --init --recursive
|
|
|
|
if ($lastExitCode -ne "0") { throw "'git submodule update' in 📂$folder failed with exit code $lastExitCode" }
|
|
|
|
$step++
|
2021-01-20 16:11:38 +01:00
|
|
|
}
|
2023-10-15 10:09:16 +02:00
|
|
|
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
|
|
|
|
"✔️ Pulled updates into $numFolders repos under 📂$parentDirName ($failed failed, took $elapsed sec)"
|
2021-09-27 10:09:45 +02:00
|
|
|
exit 0 # success
|
2021-01-20 16:11:38 +01:00
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-01-20 16:11:38 +01:00
|
|
|
exit 1
|
2022-11-05 15:53:36 +01:00
|
|
|
}
|