Skip to content

Fixed checking out non-existent branch #557

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

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Changes from all 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
@@ -25,6 +25,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)
- Make sure more fetch calls prune the remote branches (#471)
- Force export of item if it has been modified (#354)
- Production configuration page no longer closes Sync/WebUI when operations there change the production (#542)
17 changes: 16 additions & 1 deletion cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
@@ -336,7 +336,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
}
set Reload = 1
}
} elseif (menuItemName = "Sync") {
@@ -409,8 +412,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
}