diff options
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/confirmation_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/discard_changes_menu_panel.go | 4 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/patch_options_panel.go | 20 | ||||
-rw-r--r-- | pkg/gui/undoing.go | 11 |
5 files changed, 25 insertions, 18 deletions
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 0e0a3ac63..815d5a0f9 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -127,7 +127,11 @@ func (gui *Gui) createPopupPanel(g *gocui.Gui, currentView *gocui.View, title, p } gui.renderString(g, "confirmation", prompt) - return gui.setKeyBindings(g, handleConfirm, handleClose, returnFocusOnClose) + if err := gui.setKeyBindings(g, handleConfirm, handleClose, returnFocusOnClose); err != nil { + return err + } + + return gui.refreshSidePanels(refreshOptions{}) }) return nil } diff --git a/pkg/gui/discard_changes_menu_panel.go b/pkg/gui/discard_changes_menu_panel.go index 46722e1e5..0f01ad964 100644 --- a/pkg/gui/discard_changes_menu_panel.go +++ b/pkg/gui/discard_changes_menu_panel.go @@ -18,7 +18,7 @@ func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error { displayString: gui.Tr.SLocalize("discardAllChanges"), onPress: func() error { if err := gui.GitCommand.DiscardAllFileChanges(file); err != nil { - return err + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}}) }, @@ -30,7 +30,7 @@ func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error { displayString: gui.Tr.SLocalize("discardUnstagedChanges"), onPress: func() error { if err := gui.GitCommand.DiscardUnstagedFileChanges(file); err != nil { - return err + return gui.surfaceError(err) } return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []int{FILES}}) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index d3ecbdce4..7cb094837 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -130,7 +130,7 @@ func (gui *Gui) stagedFiles() []*commands.File { func (gui *Gui) trackedFiles() []*commands.File { files := gui.State.Files - result := make([]*commands.File, 0) + result := make([]*commands.File, 0, len(files)) for _, file := range files { if file.Tracked { result = append(result, file) diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index b8e88d903..e51860b43 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -113,11 +113,21 @@ func (gui *Gui) handlePullPatchIntoWorkingTree() error { return err } - return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error { - commitIndex := gui.getPatchCommitIndex() - err := gui.GitCommand.PullPatchIntoIndex(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager) - return gui.handleGenericMergeCommandResult(err) - }) + pull := func(stash bool) error { + return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error { + commitIndex := gui.getPatchCommitIndex() + err := gui.GitCommand.PullPatchIntoIndex(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager, stash) + return gui.handleGenericMergeCommandResult(err) + }) + } + + if len(gui.trackedFiles()) > 0 { + return gui.createConfirmationPanel(gui.g, gui.g.CurrentView(), true, gui.Tr.SLocalize("MustStashTitle"), gui.Tr.SLocalize("MustStashWarning"), func(*gocui.Gui, *gocui.View) error { + return pull(true) + }, nil) + } else { + return pull(false) + } } func (gui *Gui) handleApplyPatch() error { diff --git a/pkg/gui/undoing.go b/pkg/gui/undoing.go index 9ce7f7b0e..d34bfe91d 100644 --- a/pkg/gui/undoing.go +++ b/pkg/gui/undoing.go @@ -155,15 +155,6 @@ type handleHardResetWithAutoStashOptions struct { // only to be used in the undo flow for now func (gui *Gui) handleHardResetWithAutoStash(commitSha string, options handleHardResetWithAutoStashOptions) error { - // if we have any modified tracked files we need to ask the user if they want us to stash for them - dirtyWorkingTree := false - for _, file := range gui.State.Files { - if file.Tracked { - dirtyWorkingTree = true - break - } - } - reset := func() error { if err := gui.resetToRef(commitSha, "hard", commands.RunCommandOptions{EnvVars: options.EnvVars}); err != nil { return gui.surfaceError(err) @@ -171,6 +162,8 @@ func (gui *Gui) handleHardResetWithAutoStash(commitSha string, options handleHar return nil } + // if we have any modified tracked files we need to ask the user if they want us to stash for them + dirtyWorkingTree := len(gui.trackedFiles()) > 0 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 { |