summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-19 22:53:16 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-25 09:39:04 +1100
commitb1b0219f04ab0e17dd0ce0f5469dee7daecf2717 (patch)
tree8cd6cc0af919294e25f031a65aba5ce5fee18597
parentb1941c33f7ec2f6c1868a395656c0c57f7c0ac05 (diff)
autostash changes when hard resetting
-rw-r--r--pkg/gui/reflog_panel.go43
1 files changed, 38 insertions, 5 deletions
diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go
index 47f33e767..27b9a5590 100644
--- a/pkg/gui/reflog_panel.go
+++ b/pkg/gui/reflog_panel.go
@@ -3,7 +3,6 @@ package gui
import (
"regexp"
- "github.com/davecgh/go-spew/spew"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
@@ -122,7 +121,7 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
{
regexStr: `^commit|^rebase -i \(start\)`,
action: func(match []string, commitSha string, prevCommitSha string) (bool, error) {
- return true, gui.resetToRef(prevCommitSha, "hard")
+ return true, gui.handleHardResetWithAutoStash(prevCommitSha)
},
},
}
@@ -131,8 +130,6 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
for _, action := range reflogActions {
re := regexp.MustCompile(action.regexStr)
match := re.FindStringSubmatch(reflogCommit.Name)
- gui.Log.Warn(action.regexStr)
- gui.Log.Warn(spew.Sdump(match))
if len(match) == 0 {
continue
}
@@ -140,7 +137,6 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
if len(gui.State.ReflogCommits)-1 >= i+1 {
prevCommitSha = gui.State.ReflogCommits[i+1].Sha
}
- gui.Log.Warn(prevCommitSha)
done, err := action.action(match, reflogCommit.Sha, prevCommitSha)
if err != nil {
@@ -154,3 +150,40 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
return nil
}
+
+func (gui *Gui) handleHardResetWithAutoStash(commitSha string) 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
+ }
+ }
+
+ 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())
+ }
+
+ 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.resetToRef(commitSha, "hard"); err != nil {
+ return gui.createErrorPanel(gui.g, err.Error())
+ }
+
+ return gui.refreshSidePanels(gui.g)
+}