Improved switch-branch.ps1

This commit is contained in:
Markus Fleschutz 2021-02-15 10:56:22 +01:00
parent 108f3ad743
commit d42130d598

View File

@ -11,7 +11,7 @@ param($Branch = "")
try { try {
& git --version & git --version
} catch { } catch {
write-error "Can't execute 'git' - make sure Git is installed and available" write-error "ERROR: can't execute 'git' - make sure Git is installed and available"
exit 1 exit 1
} }
@ -19,11 +19,16 @@ try {
if ($Branch -eq "") { if ($Branch -eq "") {
$Branch = read-host "Enter branch name to switch to" $Branch = read-host "Enter branch name to switch to"
} }
& git switch --recurse-submodules $Branch & git switch --recurse-submodules $Branch
if ($lastExitCode -ne "0") { if ($lastExitCode -ne "0") { throw "'git switch --recurse-submodules $Branch' failed" }
throw "'git switch --recurse-submodules $Branch' failed"
} & git pull --recurse-submodules
if ($lastExitCode -ne "0") { throw "'git pull --recurse-submodules' failed" }
& git status & git status
if ($lastExitCode -ne "0") { throw "'git status' failed" }
exit 0 exit 0
} catch { } catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"