mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-20 08:58:18 +02:00
Improve switch-branch.ps1
This commit is contained in:
parent
1aef356a75
commit
0149a7e5a6
@ -1,8 +1,8 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
switch-branch.ps1 [<branch-name>] [<repo-dir>]
|
switch-branch.ps1 [<BranchName>] [<RepoDir>]
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Switches the branch in the current/given Git repository (including submodules).
|
Switches to another branch in a Git repository (including submodules).
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> .\switch-branch.ps1 main C:\MyRepo
|
PS> .\switch-branch.ps1 main C:\MyRepo
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -16,6 +16,7 @@ param([string]$BranchName = "", [string]$RepoDir = "$PWD")
|
|||||||
try {
|
try {
|
||||||
if ($BranchName -eq "") { $BranchName = read-host "Enter name of branch to switch to" }
|
if ($BranchName -eq "") { $BranchName = read-host "Enter name of branch to switch to" }
|
||||||
|
|
||||||
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||||
$RepoDir = resolve-path "$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"
|
||||||
@ -41,7 +42,8 @@ try {
|
|||||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
|
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
|
||||||
|
|
||||||
$RepoDirName = (get-item "$RepoDir").Name
|
$RepoDirName = (get-item "$RepoDir").Name
|
||||||
"✔️ switched Git repository 📂$RepoDirName to branch '$BranchName'"
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
||||||
|
"✔️ switched Git repository 📂$RepoDirName to $BranchName branch in $Elapsed sec"
|
||||||
exit 0
|
exit 0
|
||||||
} catch {
|
} catch {
|
||||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user