Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed checking out non-existent branch #557

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed git path configuration (#463)
- Added feedback to settings page (#550)
- Fix "Home" navigation to point to current namespace (#548)
- Fixed issues when user checks out nonexistent branch (#549)
- Fixed checking out branch with uncommitted work (#539)

## [2.6.0] - 2024-10-07

Expand Down
17 changes: 16 additions & 1 deletion cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
}
} elseif (menuItemName = "SwitchBranch") {
if (Answer = 1) {
do ..SwitchBranch(Msg)
set status = ..SwitchBranch(Msg)
if $$$ISERR(status) {
Quit status
isc-etamarch marked this conversation as resolved.
Show resolved Hide resolved
}
set Reload = 1
}
} elseif (menuItemName = "Sync") {
Expand Down Expand Up @@ -400,8 +403,20 @@ ClassMethod NewBranch(newBranchName As %String) As %Status

ClassMethod SwitchBranch(targetBranchName As %String) As %Status
{
// Make sure that branch exists first (-a lists both local and remote)
do ..RunGitWithArgs(.errStream,.outStream,"branch", "-a")
set branches = outStream.Read()
if ('$find(branches,targetBranchName)) {
quit $$$ERROR($$$GeneralError, "Selected branch does not exist"_$C(10))
}
k outStream, errStream
do ..RunGitWithArgs(.errStream, .outStream, "checkout", targetBranchName)
do ..PrintStreams(errStream, outStream)
// Checkout can fail due to unstaged changes
set errs = errStream.Read()
if ($find(errs, "error")) {
quit $$$ERROR($$$GeneralError, errs)
}
quit $$$OK
}

Expand Down
Loading