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

This commit is contained in:
Markus Fleschutz 2022-04-01 11:00:36 +02:00
parent 03b6623128
commit 3ac68d5826
2 changed files with 16 additions and 17 deletions

View File

@ -1,39 +1,38 @@
<#
.SYNOPSIS
Fetches updates for a Git repository
Fetches Git repository updates
.DESCRIPTION
This PowerShell script fetches updates for a local Git repository (including submodules).
.PARAMETER RepoDir
Specifies the path to the Git repository.
.EXAMPLE
PS> ./fetch-repo
🢃 Fetching updates...
fetched updates for Git repository 📂PowerShell in 14 sec
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz / License: CC0
Author: Markus Fleschutz | License: CC0
#>
param([string]$RepoDir = "$PWD")
try {
"🢃 Fetching updates..."
$StopWatch = [system.diagnostics.stopwatch]::startNew()
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
$Null = (git --version)
"⏳ Step 1/2: Checking requirements... "
& git --version
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
if (-not(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
"⏳ Step 2/2: Fetching updates... "
& git -C "$RepoDir" fetch --all --recurse-submodules --prune --prune-tags --force
if ($lastExitCode -ne "0") { throw "'git fetch' in $RepoDir failed" }
if ($lastExitCode -ne "0") { throw "'git fetch' failed with exit code $lastExitCode" }
$RepoDirName = (get-item "$RepoDir").Name
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ fetched updates for Git repository 📂$RepoDirName in $Elapsed sec"
exit 0 # success
} catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
"⚠️ Error $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
}

View File

@ -1,12 +1,12 @@
<#
.SYNOPSIS
Pulls repository updates
Pulls Git repository updates
.DESCRIPTION
This PowerShell script pulls updates for the given local Git repository (including submodules).
This PowerShell script pulls updates for a local Git repository (including submodules).
.PARAMETER RepoDir
Specifies the path to the Git repository
.EXAMPLE
PS> ./pull-repo C:\MyRepo
PS> ./pull-repo
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -29,11 +29,11 @@ try {
"⏳ Step 2/3: Pulling updates... "
& git -C "$RepoDir" pull --recurse-submodules --jobs=4
if ($lastExitCode -ne "0") { throw "'git pull' failed" }
if ($lastExitCode -ne "0") { throw "'git pull' failed with exit code $lastExitCode" }
"⏳ Step 3/3: Updating submodules... "
& git -C "$RepoDir" submodule update --init --recursive
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
if ($lastExitCode -ne "0") { throw "'git submodule update' failed with exit code $lastExitCode" }
$RepoDirName = (Get-Item "$RepoDir").Name
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds