From 3ac68d582644c74978e09ab7967354b3905ed303 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Fri, 1 Apr 2022 11:00:36 +0200 Subject: [PATCH] Update fetch-repo.ps1 and pull-repo.ps1 --- Scripts/fetch-repo.ps1 | 23 +++++++++++------------ Scripts/pull-repo.ps1 | 10 +++++----- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Scripts/fetch-repo.ps1 b/Scripts/fetch-repo.ps1 index fbfa45f2..8b4622ee 100755 --- a/Scripts/fetch-repo.ps1 +++ b/Scripts/fetch-repo.ps1 @@ -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 -} +} \ No newline at end of file diff --git a/Scripts/pull-repo.ps1 b/Scripts/pull-repo.ps1 index 62e901ec..0cb6e302 100755 --- a/Scripts/pull-repo.ps1 +++ b/Scripts/pull-repo.ps1 @@ -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