Improve both scripts

This commit is contained in:
Markus Fleschutz 2021-05-27 10:14:12 +02:00
parent 873ec7818f
commit 4d13b25eb2
2 changed files with 5 additions and 7 deletions

View File

@ -13,15 +13,14 @@ try {
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"
$RepoDirName = (get-item "$RepoDir").Name
"⏳ Pulling updates for Git repository 📂$RepoDirName ..."
$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" }
"🢃 Pulling updates..."
& git pull --recurse-submodules --jobs=4 & git pull --recurse-submodules --jobs=4
if ($lastExitCode -ne "0") { throw "'git pull' failed" } if ($lastExitCode -ne "0") { throw "'git pull' failed" }
$RepoDirName = (get-item "$RepoDir").Name
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ pulled updates for Git repository 📂$RepoDirName in $Elapsed sec." "✔️ pulled updates for Git repository 📂$RepoDirName in $Elapsed sec."
exit 0 exit 0

View File

@ -20,9 +20,7 @@ try {
if ($lastExitCode -ne "0") { throw "'git status' failed in $RepoDir" } if ($lastExitCode -ne "0") { throw "'git status' failed in $RepoDir" }
if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Git repository is NOT clean: $Result" } if ("$Result" -notmatch "nothing to commit, working tree clean") { throw "Git repository is NOT clean: $Result" }
$RepoDirName = (get-item "$RepoDir").Name "🢃 Fetching updates..."
"🢃 Fetching updates for Git repository 📂$RepoDirName ..."
& git fetch --all --recurse-submodules --jobs=4 & git fetch --all --recurse-submodules --jobs=4
if ($lastExitCode -ne "0") { throw "'git fetch -all --recurse-submodules' failed" } if ($lastExitCode -ne "0") { throw "'git fetch -all --recurse-submodules' failed" }
@ -35,7 +33,8 @@ try {
& git submodule update --init --recursive & git submodule update --init --recursive
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" } if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
"✔️ switched to branch '$BranchName'" $RepoDirName = (get-item "$RepoDir").Name
"✔️ switched Git repository 📂$RepoDirName to branch '$BranchName'"
exit 0 exit 0
} catch { } catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"