summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-21 12:49:12 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-25 09:39:04 +1100
commit7c8df28d019c3cbeac19b98a59118db03b1768fa (patch)
tree77035ed0a2d11f2f53eec89c97065400c8399a6c /pkg
parent65917272a2f5e7b8ad32f56ec98ddf5a0b51710a (diff)
add waiting status to checkout ref handler
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/branches_panel.go76
1 files changed, 39 insertions, 37 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index b4ba28ba9..227392a45 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -155,48 +155,50 @@ func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions)
waitingStatus = gui.Tr.SLocalize("CheckingOutStatus")
}
- if err := gui.GitCommand.Checkout(ref, false); err != nil {
- // note, this will only work for english-language git commands. If we force git to use english, and the error isn't this one, then the user will receive an english command they may not understand. I'm not sure what the best solution to this is. Running the command once in english and a second time in the native language is one option
-
- if strings.Contains(err.Error(), "Please commit your changes or stash them before you switch branch") {
- // offer to autostash changes
- return gui.createConfirmationPanel(gui.g, gui.getBranchesView(), true, gui.Tr.SLocalize("AutoStashTitle"), gui.Tr.SLocalize("AutoStashPrompt"), func(g *gocui.Gui, v *gocui.View) error {
-
- if err := gui.GitCommand.StashSave(gui.Tr.SLocalize("StashPrefix") + ref); err != nil {
- return gui.createErrorPanel(g, err.Error())
- }
- if err := gui.GitCommand.Checkout(ref, false); err != nil {
- return gui.createErrorPanel(g, err.Error())
- }
- if onDone != nil {
- onDone()
- }
-
- // checkout successful so we select the new branch
- gui.State.Panels.Branches.SelectedLine = 0
-
- if err := gui.GitCommand.StashDo(0, "pop"); err != nil {
- if err := gui.refreshSidePanels(g); err != nil {
- return err
+ return gui.WithWaitingStatus(waitingStatus, func() error {
+ if err := gui.GitCommand.Checkout(ref, false); err != nil {
+ // note, this will only work for english-language git commands. If we force git to use english, and the error isn't this one, then the user will receive an english command they may not understand. I'm not sure what the best solution to this is. Running the command once in english and a second time in the native language is one option
+
+ if strings.Contains(err.Error(), "Please commit your changes or stash them before you switch branch") {
+ // offer to autostash changes
+ return gui.createConfirmationPanel(gui.g, gui.getBranchesView(), true, gui.Tr.SLocalize("AutoStashTitle"), gui.Tr.SLocalize("AutoStashPrompt"), func(g *gocui.Gui, v *gocui.View) error {
+
+ if err := gui.GitCommand.StashSave(gui.Tr.SLocalize("StashPrefix") + ref); err != nil {
+ return gui.createErrorPanel(g, err.Error())
+ }
+ if err := gui.GitCommand.Checkout(ref, false); err != nil {
+ return gui.createErrorPanel(g, err.Error())
+ }
+ if onDone != nil {
+ onDone()
}
- return gui.createErrorPanel(g, err.Error())
- }
- return gui.refreshSidePanels(g)
- }, nil)
- }
- if err := gui.createErrorPanel(gui.g, err.Error()); err != nil {
- return err
+ // checkout successful so we select the new branch
+ gui.State.Panels.Branches.SelectedLine = 0
+
+ if err := gui.GitCommand.StashDo(0, "pop"); err != nil {
+ if err := gui.refreshSidePanels(g); err != nil {
+ return err
+ }
+ return gui.createErrorPanel(g, err.Error())
+ }
+ return gui.refreshSidePanels(g)
+ }, nil)
+ }
+
+ if err := gui.createErrorPanel(gui.g, err.Error()); err != nil {
+ return err
+ }
}
- }
- if onDone != nil {
- onDone()
- }
+ if onDone != nil {
+ onDone()
+ }
- gui.State.Panels.Branches.SelectedLine = 0
- gui.State.Panels.Commits.SelectedLine = 0
- return gui.refreshSidePanels(gui.g)
+ gui.State.Panels.Branches.SelectedLine = 0
+ gui.State.Panels.Commits.SelectedLine = 0
+ return gui.refreshSidePanels(gui.g)
+ })
}
func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error {