Update fetch-repo.ps1 and pull-repo.ps1

This commit is contained in:
Markus Fleschutz 2023-04-19 08:28:30 +02:00
parent aa335d38d2
commit ffaa48e228
2 changed files with 8 additions and 8 deletions

View File

@ -1,10 +1,10 @@
<#
.SYNOPSIS
Fetches repo updates
Fetches Git repo updates
.DESCRIPTION
This PowerShell script fetches the latest updates into a local Git repository (including submodules).
.PARAMETER RepoDir
Specifies the path to the Git repository.
Specifies the file path to the local Git repository (default is working directory).
.EXAMPLE
PS> ./fetch-repo C:\MyRepo
.LINK
@ -22,11 +22,11 @@ try {
& git --version
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
Write-Host "⏳ (2/3) Checking local repository... 📂$RepoDir"
Write-Host "⏳ (2/3) Checking repository... 📂$RepoDir"
if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
$RepoDirName = (Get-Item "$RepoDir").Name
Write-Host "⏳ (3/3) Fetching latest updates... "
Write-Host "⏳ (3/3) Fetching updates... "
& git -C "$RepoDir" fetch --all --recurse-submodules --prune --prune-tags --force
if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" }

View File

@ -1,6 +1,6 @@
<#
.SYNOPSIS
Pulls repo updates
Pulls Git repo updates
.DESCRIPTION
This PowerShell script pulls the latest updates into a local Git repository (including submodules).
.PARAMETER RepoDir
@ -22,13 +22,13 @@ try {
& git --version
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
Write-Host "⏳ (2/4) Checking local repository... 📂$RepoDir"
Write-Host "⏳ (2/4) Checking repository... 📂$RepoDir"
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
$Result = (git -C "$RepoDir" status)
if ("$Result" -match "HEAD detached at ") { throw "Currently in detached HEAD state (not on a branch!), so nothing to pull" }
$RepoDirName = (Get-Item "$RepoDir").Name
Write-Host "⏳ (3/4) Pulling latest updates..."
Write-Host "⏳ (3/4) Pulling updates..."
& git -C "$RepoDir" pull --recurse-submodules=yes
if ($lastExitCode -ne "0") { throw "'git pull' failed with exit code $lastExitCode" }
@ -37,7 +37,7 @@ try {
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ pulled updates into repo 📂$RepoDirName in $Elapsed sec"
"✔️ updated repo 📂$RepoDirName in $Elapsed sec"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"