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 .SYNOPSIS
Fetches repo updates Fetches Git repo updates
.DESCRIPTION .DESCRIPTION
This PowerShell script fetches the latest updates into a local Git repository (including submodules). This PowerShell script fetches the latest updates into a local Git repository (including submodules).
.PARAMETER RepoDir .PARAMETER RepoDir
Specifies the path to the Git repository. Specifies the file path to the local Git repository (default is working directory).
.EXAMPLE .EXAMPLE
PS> ./fetch-repo C:\MyRepo PS> ./fetch-repo C:\MyRepo
.LINK .LINK
@ -22,11 +22,11 @@ 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" }
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" } if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
$RepoDirName = (Get-Item "$RepoDir").Name $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 & git -C "$RepoDir" fetch --all --recurse-submodules --prune --prune-tags --force
if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" } if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" }

View File

@ -1,6 +1,6 @@
<# <#
.SYNOPSIS .SYNOPSIS
Pulls repo updates Pulls Git repo updates
.DESCRIPTION .DESCRIPTION
This PowerShell script pulls the latest updates into a local Git repository (including submodules). This PowerShell script pulls the latest updates into a local Git repository (including submodules).
.PARAMETER RepoDir .PARAMETER RepoDir
@ -22,13 +22,13 @@ 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" }
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" } if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
$Result = (git -C "$RepoDir" status) $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" } 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 $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 & git -C "$RepoDir" pull --recurse-submodules=yes
if ($lastExitCode -ne "0") { throw "'git pull' failed with exit code $lastExitCode" } 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" } if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ pulled updates into repo 📂$RepoDirName in $Elapsed sec" "✔️ updated 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])"