Improve output of fetch-repo.ps1 and pull-repo.ps1

This commit is contained in:
Markus Fleschutz 2021-04-20 08:06:33 +02:00
parent bb5e5d4b82
commit e9dd4329b0
2 changed files with 13 additions and 8 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/pwsh #!/usr/bin/pwsh
<# <#
.SYNTAX fetch-repo.ps1 [<repo-dir>] .SYNTAX fetch-repo.ps1 [<repo-dir>]
.DESCRIPTION fetches updates for the current/given Git repository (including submodules) .DESCRIPTION fetches updates for a local Git repository (including submodules)
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
@ -9,14 +9,18 @@
param($RepoDir = "$PWD") param($RepoDir = "$PWD")
try { try {
"⏳ Fetching updates for Git repository $($RepoDir)..." $RepoDir = resolve-path "$RepoDir"
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
set-location "$RepoDir" set-location "$RepoDir"
"⏳ Fetching updates for Git repository 📂$RepoDir ..."
$Null = (git --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
& git fetch --all --recurse-submodules --jobs=4 & git fetch --all --recurse-submodules --jobs=4
if ($lastExitCode -ne "0") { if ($lastExitCode -ne "0") {
# retry once: write-warning "Retrying once ..."
start-sleep -milliseconds 1000 start-sleep -milliseconds 1000
& git fetch --all --recurse-submodules --jobs=1 & git fetch --all --recurse-submodules --jobs=1
if ($lastExitCode -ne "0") { throw "'git fetch' failed (twice)" } if ($lastExitCode -ne "0") { throw "'git fetch' failed (twice)" }

View File

@ -1,7 +1,7 @@
#!/usr/bin/pwsh #!/usr/bin/pwsh
<# <#
.SYNTAX pull-repo.ps1 [<repo-dir>] .SYNTAX pull-repo.ps1 [<repo-dir>]
.DESCRIPTION pulls updates a Git repository (including submodules) .DESCRIPTION pulls updates for a local Git repository (including submodules)
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
@ -9,18 +9,19 @@
param($RepoDir = "$PWD") param($RepoDir = "$PWD")
try { try {
"⏳ Pulling updates for Git repository $($RepoDir)..." $RepoDir = resolve-path "$RepoDir"
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" } if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
set-location "$RepoDir" set-location "$RepoDir"
"⏳ Updating Git repository 📂$RepoDir ..."
$Null = (git --version) $Null = (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" }
& git pull --all --recurse-submodules --jobs=4 & git pull --all --recurse-submodules --jobs=4
if ($lastExitCode -ne "0") { throw "'git pull' failed" } if ($lastExitCode -ne "0") { throw "'git pull' failed" }
"✔️ Git repository $RepoDir is up to date" "✔️ updated Git repository 📂$RepoDir"
exit 0 exit 0
} catch { } catch {
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"