Improved check for $lastExitCode

This commit is contained in:
Markus Fleschutz
2025-02-24 20:42:52 +01:00
parent c6929fc266
commit e36021f3b2
91 changed files with 204 additions and 204 deletions

View File

@ -26,11 +26,11 @@ try {
if (-not(Test-Path "$pathToRepo" -pathType container)) { throw "Can't access directory: $pathToRepo" }
$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" }
Write-Progress "Fetching latest updates..."
& git -C "$pathToRepo" fetch --all --quiet
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
if ($lastExitCode -ne 0) { throw "'git fetch' failed" }
Write-Progress -Completed "Done."
if ($format -eq "pretty") {
@ -46,7 +46,7 @@ try {
"List of Git Commits"
"-------------------"
& git -C "$pathToRepo" log --graph --pretty=format:'%Cred%h%Creset%C(yellow)%d%Creset %s %C(bold blue)by %an %cr%Creset' --abbrev-commit
if ($lastExitCode -ne "0") { throw "'git log' failed" }
if ($lastExitCode -ne 0) { throw "'git log' failed" }
} elseif ($format -eq "JSON") {
& git -C "$pathToRepo" log --pretty=format:'{%n "commit": "%H",%n "abbreviated_commit": "%h",%n "tree": "%T",%n "abbreviated_tree": "%t",%n "parent": "%P",%n "abbreviated_parent": "%p",%n "refs": "%D",%n "encoding": "%e",%n "subject": "%s",%n "sanitized_subject_line": "%f",%n "body": "%b",%n "commit_notes": "%N",%n "verification_flag": "%G?",%n "signer": "%GS",%n "signer_key": "%GK",%n "author": {%n "name": "%aN",%n "email": "%aE",%n "date": "%aD"%n },%n "commiter": {%n "name": "%cN",%n "email": "%cE",%n "date": "%cD"%n }%n},'
} else {
@ -54,7 +54,7 @@ try {
"List of Git Commits"
"-------------------"
& git -C "$pathToRepo" log
if ($lastExitCode -ne "0") { throw "'git log' failed" }
if ($lastExitCode -ne 0) { throw "'git log' failed" }
}
exit 0 # success
} catch {