summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-21 12:40:56 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-25 09:39:04 +1100
commit65917272a2f5e7b8ad32f56ec98ddf5a0b51710a (patch)
treef89e7740158d292caa95910122d2b6b0e3f25ef6
parent137fd80fdbcdeabd9e37732b9c8fa34f3052f1eb (diff)
undoing status
-rw-r--r--pkg/gui/branches_panel.go18
-rw-r--r--pkg/gui/commits_panel.go2
-rw-r--r--pkg/gui/reflog_panel.go44
-rw-r--r--pkg/gui/remote_branches_panel.go2
-rw-r--r--pkg/gui/tags_panel.go2
-rw-r--r--pkg/i18n/english.go6
6 files changed, 48 insertions, 26 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index 49a0f0963..b4ba28ba9 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -106,7 +106,7 @@ func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error {
return gui.createErrorPanel(g, gui.Tr.SLocalize("AlreadyCheckedOutBranch"))
}
branch := gui.getSelectedBranch()
- return gui.handleCheckoutRef(branch.Name, nil)
+ return gui.handleCheckoutRef(branch.Name, handleCheckoutRefOptions{})
}
func (gui *Gui) handleCreatePullRequestPress(g *gocui.Gui, v *gocui.View) error {
@@ -143,13 +143,25 @@ func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error {
}, nil)
}
-func (gui *Gui) handleCheckoutRef(ref string, onDone func()) error {
+type handleCheckoutRefOptions struct {
+ onDone func()
+ waitingStatus string
+}
+
+func (gui *Gui) handleCheckoutRef(ref string, options handleCheckoutRefOptions) error {
+ onDone := options.onDone
+ waitingStatus := options.waitingStatus
+ if waitingStatus == "" {
+ 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())
}
@@ -189,7 +201,7 @@ func (gui *Gui) handleCheckoutRef(ref string, onDone func()) error {
func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error {
return gui.createPromptPanel(g, v, gui.Tr.SLocalize("BranchName")+":", "", func(g *gocui.Gui, v *gocui.View) error {
- return gui.handleCheckoutRef(gui.trimmedContent(v), nil)
+ return gui.handleCheckoutRef(gui.trimmedContent(v), handleCheckoutRefOptions{})
})
}
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 88ec76d04..a31cd863a 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -540,7 +540,7 @@ func (gui *Gui) handleCheckoutCommit(g *gocui.Gui, v *gocui.View) error {
}
return gui.createConfirmationPanel(g, gui.getCommitsView(), true, gui.Tr.SLocalize("checkoutCommit"), gui.Tr.SLocalize("SureCheckoutThisCommit"), func(g *gocui.Gui, v *gocui.View) error {
- return gui.handleCheckoutRef(commit.Sha, nil)
+ return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{})
}, nil)
}
diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go
index 4bdfddb54..3da4caeb1 100644
--- a/pkg/gui/reflog_panel.go
+++ b/pkg/gui/reflog_panel.go
@@ -85,7 +85,7 @@ func (gui *Gui) handleCheckoutReflogCommit(g *gocui.Gui, v *gocui.View) error {
}
err := gui.createConfirmationPanel(g, gui.getCommitsView(), true, gui.Tr.SLocalize("checkoutCommit"), gui.Tr.SLocalize("SureCheckoutThisCommit"), func(g *gocui.Gui, v *gocui.View) error {
- return gui.handleCheckoutRef(commit.Sha, nil)
+ return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{})
}, nil)
if err != nil {
return err
@@ -137,7 +137,7 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
if len(match) <= 1 {
return false, nil
}
- return true, gui.handleCheckoutRef(match[1], onDone)
+ return true, gui.handleCheckoutRef(match[1], handleCheckoutRefOptions{onDone: onDone, waitingStatus: gui.Tr.SLocalize("UndoingStatus")})
},
},
{
@@ -198,27 +198,31 @@ func (gui *Gui) handleHardResetWithAutoStash(commitSha string, onDone func()) er
if dirtyWorkingTree {
// 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") + commitSha); err != nil {
- return gui.createErrorPanel(g, err.Error())
- }
- if err := gui.resetToRef(commitSha, "hard"); err != nil {
- return gui.createErrorPanel(g, err.Error())
- }
- onDone()
+ return gui.WithWaitingStatus(gui.Tr.SLocalize("UndoingStatus"), func() error {
+ if err := gui.GitCommand.StashSave(gui.Tr.SLocalize("StashPrefix") + commitSha); err != nil {
+ return gui.createErrorPanel(g, err.Error())
+ }
+ if err := gui.resetToRef(commitSha, "hard"); err != nil {
+ return gui.createErrorPanel(g, err.Error())
+ }
+ onDone()
- if err := gui.GitCommand.StashDo(0, "pop"); err != nil {
- if err := gui.refreshSidePanels(g); err != nil {
- return err
+ 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.createErrorPanel(g, err.Error())
- }
- return gui.refreshSidePanels(g)
+ return gui.refreshSidePanels(g)
+ })
}, nil)
}
- if err := gui.resetToRef(commitSha, "hard"); err != nil {
- return gui.createErrorPanel(gui.g, err.Error())
- }
- onDone()
- return gui.refreshSidePanels(gui.g)
+ return gui.WithWaitingStatus(gui.Tr.SLocalize("UndoingStatus"), func() error {
+ if err := gui.resetToRef(commitSha, "hard"); err != nil {
+ return gui.createErrorPanel(gui.g, err.Error())
+ }
+ onDone()
+ return gui.refreshSidePanels(gui.g)
+ })
}
diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go
index 28270dac2..ffc353de4 100644
--- a/pkg/gui/remote_branches_panel.go
+++ b/pkg/gui/remote_branches_panel.go
@@ -76,7 +76,7 @@ func (gui *Gui) handleCheckoutRemoteBranch(g *gocui.Gui, v *gocui.View) error {
if remoteBranch == nil {
return nil
}
- if err := gui.handleCheckoutRef(remoteBranch.RemoteName+"/"+remoteBranch.Name, nil); err != nil {
+ if err := gui.handleCheckoutRef(remoteBranch.RemoteName+"/"+remoteBranch.Name, handleCheckoutRefOptions{}); err != nil {
return err
}
return gui.switchBranchesPanelContext("local-branches")
diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go
index b92727e8c..0599525b0 100644
--- a/pkg/gui/tags_panel.go
+++ b/pkg/gui/tags_panel.go
@@ -81,7 +81,7 @@ func (gui *Gui) handleCheckoutTag(g *gocui.Gui, v *gocui.View) error {
if tag == nil {
return nil
}
- if err := gui.handleCheckoutRef(tag.Name, nil); err != nil {
+ if err := gui.handleCheckoutRef(tag.Name, handleCheckoutRefOptions{}); err != nil {
return err
}
return gui.switchBranchesPanelContext("local-branches")
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index 37b6340b1..d63d330bf 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -745,6 +745,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
ID: "CherryPickingStatus",
Other: "cherry-picking",
}, &i18n.Message{
+ ID: "UndoingStatus",
+ Other: "undoing",
+ }, &i18n.Message{
+ ID: "CheckingOutStatus",
+ Other: "checking out",
+ }, &i18n.Message{
ID: "CommitFiles",
Other: "Commit files",
}, &i18n.Message{