Skip to content

Commit ead95c8

Browse files
authored
Merge pull request #557 from intersystems/issue-549
Fixed checking out non-existent branch
2 parents 708ce31 + 5f1a1e5 commit ead95c8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- Fixed git path configuration (#463)
2626
- Added feedback to settings page (#550)
2727
- Fix "Home" navigation to point to current namespace (#548)
28+
- Fixed issues when user checks out nonexistent branch (#549)
29+
- Fixed checking out branch with uncommitted work (#539)
2830
- Make sure more fetch calls prune the remote branches (#471)
2931
- Force export of item if it has been modified (#354)
3032
- Production configuration page no longer closes Sync/WebUI when operations there change the production (#542)

cls/SourceControl/Git/Utils.cls

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
336336
}
337337
} elseif (menuItemName = "SwitchBranch") {
338338
if (Answer = 1) {
339-
do ..SwitchBranch(Msg)
339+
set status = ..SwitchBranch(Msg)
340+
if $$$ISERR(status) {
341+
Quit status
342+
}
340343
set Reload = 1
341344
}
342345
} elseif (menuItemName = "Sync") {
@@ -409,8 +412,20 @@ ClassMethod NewBranch(newBranchName As %String) As %Status
409412

410413
ClassMethod SwitchBranch(targetBranchName As %String) As %Status
411414
{
415+
// Make sure that branch exists first (-a lists both local and remote)
416+
do ..RunGitWithArgs(.errStream,.outStream,"branch", "-a")
417+
set branches = outStream.Read()
418+
if ('$find(branches,targetBranchName)) {
419+
quit $$$ERROR($$$GeneralError, "Selected branch does not exist"_$C(10))
420+
}
421+
k outStream, errStream
412422
do ..RunGitWithArgs(.errStream, .outStream, "checkout", targetBranchName)
413423
do ..PrintStreams(errStream, outStream)
424+
// Checkout can fail due to unstaged changes
425+
set errs = errStream.Read()
426+
if ($find(errs, "error")) {
427+
quit $$$ERROR($$$GeneralError, errs)
428+
}
414429
quit $$$OK
415430
}
416431

0 commit comments

Comments
 (0)