Update sync-repo.ps1

This commit is contained in:
Markus Fleschutz 2022-03-25 07:28:12 +01:00
parent 45d72ecc4b
commit b0330be96c

View File

@ -16,22 +16,25 @@
param([string]$RepoDir = "$PWD") param([string]$RepoDir = "$PWD")
try { try {
$StopWatch = [system.diagnostics.stopwatch]::startNew()
"⏳ Step 1/3: Checking requirements..."
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
set-location "$RepoDir"
$RepoDirName = (Get-Item "$RepoDir").Name
"⏳ Synchronizing Git repository 📂$RepoDirName ..." & git --version
$Null = (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" }
& git push "⏳ Step 2/3: Pushing local updates..."
& git -C "$RepoDir" push
if ($lastExitCode -ne "0") { throw "'git push' failed" } if ($lastExitCode -ne "0") { throw "'git push' failed" }
& git pull --all --recurse-submodules --jobs=4 "⏳ Step 3/3: Pulling remote updates..."
& git -C "$RepoDir" pull --all --recurse-submodules --jobs=4
if ($lastExitCode -ne "0") { throw "'git pull' failed" } if ($lastExitCode -ne "0") { throw "'git pull' failed" }
"✔️ synchronized Git repository 📂$RepoDirName" $RepoDirName = (Get-Item "$RepoDir").Name
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ synchronized Git repo 📂$RepoDirName in $Elapsed sec"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))" "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"