summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-11-05 11:53:01 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-05 19:22:01 +1100
commit0ffccbd3ee952a441575f378ce70b8be94e9f3c5 (patch)
tree328525fdcdc9615fe95ada5399f7814d3c7565ce /pkg
parent1fc120de2d4a28b976920cd3ac5393bf4c040705 (diff)
checks for if we're in a normal working tree state
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/commit_files_panel.go12
-rw-r--r--pkg/gui/patch_options_panel.go19
-rw-r--r--pkg/i18n/english.go3
3 files changed, 31 insertions, 3 deletions
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go
index a8e5b2f4f..2ee108116 100644
--- a/pkg/gui/commit_files_panel.go
+++ b/pkg/gui/commit_files_panel.go
@@ -64,6 +64,10 @@ func (gui *Gui) handleCheckoutCommitFile(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) handleDiscardOldFileChange(g *gocui.Gui, v *gocui.View) error {
+ if ok, err := gui.validateNormalWorkingTreeState(); !ok {
+ return err
+ }
+
fileName := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLine].Name
return gui.createConfirmationPanel(gui.g, v, gui.Tr.SLocalize("DiscardFileChangesTitle"), gui.Tr.SLocalize("DiscardFileChangesPrompt"), func(g *gocui.Gui, v *gocui.View) error {
@@ -110,6 +114,10 @@ func (gui *Gui) handleOpenOldCommitFile(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
+ if ok, err := gui.validateNormalWorkingTreeState(); !ok {
+ return err
+ }
+
commitFile := gui.getSelectedCommitFile(g)
if commitFile == nil {
return gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
@@ -157,6 +165,10 @@ func (gui *Gui) createPatchManager() error {
}
func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error {
+ if ok, err := gui.validateNormalWorkingTreeState(); !ok {
+ return err
+ }
+
commitFile := gui.getSelectedCommitFile(g)
if commitFile == nil {
return gui.renderString(g, "commitFiles", gui.Tr.SLocalize("NoCommiteFiles"))
diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go
index 14d13cd82..5e2329703 100644
--- a/pkg/gui/patch_options_panel.go
+++ b/pkg/gui/patch_options_panel.go
@@ -54,7 +54,9 @@ func (gui *Gui) getPatchCommitIndex() int {
}
func (gui *Gui) handleDeletePatchFromCommit() error {
- // TODO: deal with when we're already rebasing
+ if ok, err := gui.validateNormalWorkingTreeState(); !ok {
+ return err
+ }
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
@@ -64,7 +66,9 @@ func (gui *Gui) handleDeletePatchFromCommit() error {
}
func (gui *Gui) handleMovePatchToSelectedCommit() error {
- // TODO: deal with when we're already rebasing
+ if ok, err := gui.validateNormalWorkingTreeState(); !ok {
+ return err
+ }
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
@@ -73,8 +77,17 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
})
}
+func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
+ if gui.State.WorkingTreeState != "normal" {
+ return false, gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantPatchWhileRebasingError"))
+ }
+ return true, nil
+}
+
func (gui *Gui) handlePullPatchIntoWorkingTree() error {
- // TODO: deal with when we're already rebasing
+ if ok, err := gui.validateNormalWorkingTreeState(); !ok {
+ return err
+ }
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index d5f46ac2d..5d5bb5cc4 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -801,6 +801,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
ID: "DiscardPatchConfirm",
Other: "You can only build a patch from one commit at a time. Discard current patch?",
}, &i18n.Message{
+ ID: "CantPatchWhileRebasingError",
+ Other: "You cannot build a patch or run patch commands while in a merging or rebasing state",
+ }, &i18n.Message{
ID: "toggleAddToPatch",
Other: "toggle file included in patch",
}, &i18n.Message{