2021-02-13 10:26:14 +01:00
|
|
|
#!/bin/powershell
|
|
|
|
<#
|
|
|
|
.SYNTAX ./switch-branch.ps1 [<branch>]
|
2021-02-21 12:24:22 +01:00
|
|
|
.DESCRIPTION switches the current Git repository to the given branch (including submodules)
|
2021-02-13 10:26:14 +01:00
|
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES Author: Markus Fleschutz / License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
param($Branch = "")
|
|
|
|
|
2021-02-18 20:17:55 +01:00
|
|
|
if ($Branch -eq "") {
|
|
|
|
$Branch = read-host "Enter branch name to switch to"
|
|
|
|
}
|
|
|
|
|
2021-02-13 10:26:14 +01:00
|
|
|
try {
|
|
|
|
& git --version
|
|
|
|
} catch {
|
2021-02-15 10:56:22 +01:00
|
|
|
write-error "ERROR: can't execute 'git' - make sure Git is installed and available"
|
2021-02-13 10:26:14 +01:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
& git switch --recurse-submodules $Branch
|
2021-02-15 10:56:22 +01:00
|
|
|
if ($lastExitCode -ne "0") { throw "'git switch --recurse-submodules $Branch' failed" }
|
|
|
|
|
2021-02-15 11:34:05 +01:00
|
|
|
& git submodule update --init --recursive
|
|
|
|
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
|
|
|
|
|
2021-02-15 10:56:22 +01:00
|
|
|
& git pull --recurse-submodules
|
2021-02-15 11:34:05 +01:00
|
|
|
if ($lastExitCode -ne "0") { throw "'git pull' failed" }
|
2021-02-15 10:56:22 +01:00
|
|
|
|
2021-02-15 10:39:46 +01:00
|
|
|
& git status
|
2021-02-15 10:56:22 +01:00
|
|
|
if ($lastExitCode -ne "0") { throw "'git status' failed" }
|
|
|
|
|
2021-02-13 10:26:14 +01:00
|
|
|
exit 0
|
|
|
|
} catch {
|
2021-02-16 10:03:20 +01:00
|
|
|
write-error "ERROR: line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-02-13 10:26:14 +01:00
|
|
|
exit 1
|
|
|
|
}
|