Skip to content

Commit b3663ae

Browse files
committed
Fix user checking out nonexistent branch
1 parent c62aac2 commit b3663ae

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Fixed git path configuration (#463)
2121
- Added feedback to settings page (#550)
2222
- Fix "Home" navigation to point to current namespace (#548)
23+
- Fixed issues when user checks out nonexistent branch (#549)
2324

2425
## [2.6.0] - 2024-10-07
2526

cls/SourceControl/Git/Utils.cls

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
327327
}
328328
} elseif (menuItemName = "SwitchBranch") {
329329
if (Answer = 1) {
330-
do ..SwitchBranch(Msg)
330+
set status = ..SwitchBranch(Msg)
331+
if $$$ISERR(status) {
332+
Quit status
333+
}
331334
set Reload = 1
332335
}
333336
} elseif (menuItemName = "Sync") {
@@ -400,6 +403,13 @@ ClassMethod NewBranch(newBranchName As %String) As %Status
400403

401404
ClassMethod SwitchBranch(targetBranchName As %String) As %Status
402405
{
406+
// Make sure that branch exists first
407+
do ..RunGitWithArgs(.errStream,.outStream,"local-branches","branch", "--verbose")
408+
set branches = outStream.Read()
409+
if ('$find(branches,targetBranchName)) {
410+
quit $$$ERROR($$$GeneralError, "Branch does not exist")
411+
}
412+
k outStream, errStream
403413
do ..RunGitWithArgs(.errStream, .outStream, "checkout", targetBranchName)
404414
do ..PrintStreams(errStream, outStream)
405415
quit $$$OK

0 commit comments

Comments
 (0)