PowerShell/Scripts/update-repos.ps1

35 lines
864 B
PowerShell
Raw Normal View History

2021-02-09 19:30:45 +01:00
#!/bin/powershell
2021-01-20 16:11:38 +01:00
<#
2021-02-28 18:49:53 +01:00
.SYNTAX ./update-repos.ps1 [<parent-dir>]
2021-02-21 12:24:22 +01:00
.DESCRIPTION updates all Git repositories under the current/given directory (including submodules)
2021-01-20 16:11:38 +01:00
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
2021-02-28 18:49:53 +01:00
param($ParentDir = "$PWD")
2021-02-18 20:17:55 +01:00
2021-02-13 10:26:14 +01:00
try {
& git --version
} catch {
2021-02-15 12:00:23 +01:00
write-error "ERROR: can't execute 'git' - make sure Git is installed and available"
2021-02-13 10:26:14 +01:00
exit 1
}
2021-01-20 16:11:38 +01:00
try {
2021-02-28 18:49:53 +01:00
set-location $ParentDir
get-childItem $ParentDir -attributes Directory | foreach-object {
set-location $_.FullName
write-host ""
write-host -nonewline "Updating $($_.FullName)..."
& git pull --recurse-submodules
if ($lastExitCode -ne "0") { throw "'git pull --recurse-submodules' failed" }
set-location ..
2021-01-20 16:11:38 +01:00
}
exit 0
} catch {
2021-02-15 12:00:23 +01:00
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-01-20 16:11:38 +01:00
exit 1
}