Update sync-repo.ps1

This commit is contained in:
Markus Fleschutz 2023-04-12 11:35:57 +02:00
parent 99c5a5e240
commit ad4fc918ef

View File

@ -1,8 +1,8 @@
<# <#
.SYNOPSIS .SYNOPSIS
Syncs a Git repo Synchronizes a repo
.DESCRIPTION .DESCRIPTION
This PowerShell script synchronizes a Git repository by push & pull (including submodules). This PowerShell script synchronizes a local Git repository by push and pull (including submodules).
.PARAMETER RepoDir .PARAMETER RepoDir
Specifies the path to the Git repository Specifies the path to the Git repository
.EXAMPLE .EXAMPLE
@ -22,9 +22,9 @@ try {
& 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" }
$RepoDirName = (Get-Item "$RepoDir").Name Write-Host "⏳ (2/4) Checking local repository... 📂$RepoDir"
Write-Host "⏳ (2/4) Checking Git repository... 📂$RepoDirName"
if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" } if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
$RepoDirName = (Get-Item "$RepoDir").Name
Write-Host "⏳ (3/4) Pushing local updates... " -noNewline Write-Host "⏳ (3/4) Pushing local updates... " -noNewline
& git -C "$RepoDir" push & git -C "$RepoDir" push
@ -35,7 +35,7 @@ try {
if ($lastExitCode -ne "0") { throw "'git pull' failed" } if ($lastExitCode -ne "0") { throw "'git pull' failed" }
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ synchronized 📂$RepoDirName repository in $Elapsed sec." "✔️ synchronized repo 📂$RepoDirName 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])"