mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-23 00:13:36 +01:00
Improve switch-branch.ps1
This commit is contained in:
parent
1aef356a75
commit
0149a7e5a6
@ -1,8 +1,8 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
switch-branch.ps1 [<branch-name>] [<repo-dir>]
|
||||
switch-branch.ps1 [<BranchName>] [<RepoDir>]
|
||||
.DESCRIPTION
|
||||
Switches the branch in the current/given Git repository (including submodules).
|
||||
Switches to another branch in a Git repository (including submodules).
|
||||
.EXAMPLE
|
||||
PS> .\switch-branch.ps1 main C:\MyRepo
|
||||
.NOTES
|
||||
@ -16,6 +16,7 @@ param([string]$BranchName = "", [string]$RepoDir = "$PWD")
|
||||
try {
|
||||
if ($BranchName -eq "") { $BranchName = read-host "Enter name of branch to switch to" }
|
||||
|
||||
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
||||
$RepoDir = resolve-path "$RepoDir"
|
||||
if (-not(test-path "$RepoDir" -pathType container)) { throw "Can't access directory: $RepoDir" }
|
||||
set-location "$RepoDir"
|
||||
@ -41,7 +42,8 @@ try {
|
||||
if ($lastExitCode -ne "0") { throw "'git submodule update' failed" }
|
||||
|
||||
$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
|
||||
} catch {
|
||||
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
Loading…
Reference in New Issue
Block a user