diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-06 15:13:40 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-06 19:34:32 +1000 |
commit | 0719a3e36e530ebc6716538ef4581d1929df8ab9 (patch) | |
tree | 5f780d16a66c50110a79ecd73aa4295e7797cd17 /pkg/gui/branches_panel.go | |
parent | a3b0efb82e5a1883d0d89fa48a718858427daf49 (diff) |
stop checking out branches when doing a rename. Instead just move the cursor to the new position
Diffstat (limited to 'pkg/gui/branches_panel.go')
-rw-r--r-- | pkg/gui/branches_panel.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 6f88e3843..a24c6a7e9 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -428,9 +428,6 @@ func (gui *Gui) handleRenameBranch() error { return nil } - // TODO: find a way to not checkout the branch here if it's not the current branch (i.e. find some - // way to get it to show up in the reflog) - promptForNewName := func() error { return gui.prompt(promptOpts{ title: gui.Tr.NewBranchNamePrompt + " " + branch.Name + ":", @@ -439,13 +436,21 @@ func (gui *Gui) handleRenameBranch() error { if err := gui.GitCommand.RenameBranch(branch.Name, newBranchName); err != nil { return gui.surfaceError(err) } - // need to checkout so that the branch shows up in our reflog and therefore - // doesn't get lost among all the other branches when we switch to something else - if err := gui.GitCommand.Checkout(newBranchName, commands.CheckoutOptions{Force: false}); err != nil { - return gui.surfaceError(err) + + // need to find where the branch is now so that we can re-select it. That means we need to refetch the branches synchronously and then find our branch + gui.refreshBranches() + + // now that we've got our stuff again we need to find that branch and reselect it. + for i, newBranch := range gui.State.Branches { + if newBranch.Name == newBranchName { + gui.State.Panels.Branches.SetSelectedLineIdx(i) + if err := gui.State.Contexts.Branches.HandleRender(); err != nil { + return err + } + } } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + return nil }, }) } |