summaryrefslogtreecommitdiffstats
path: root/pkg/gui/reflog_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-03-21 13:39:20 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-03-25 09:39:04 +1100
commitdaecdd7c2b678e308b01d9e402c86c06a35b8021 (patch)
treeef32431a5e9b35e702b75a478d5c19b971ad1aa5 /pkg/gui/reflog_panel.go
parent7c8df28d019c3cbeac19b98a59118db03b1768fa (diff)
redoing
Diffstat (limited to 'pkg/gui/reflog_panel.go')
-rw-r--r--pkg/gui/reflog_panel.go83
1 files changed, 70 insertions, 13 deletions
diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go
index 3da4caeb1..f0172d7f2 100644
--- a/pkg/gui/reflog_panel.go
+++ b/pkg/gui/reflog_panel.go
@@ -104,7 +104,7 @@ func (gui *Gui) handleCreateReflogResetMenu(g *gocui.Gui, v *gocui.View) error {
type reflogAction struct {
regexStr string
- action func(match []string, commitSha string, prevCommitSha string, onDone func()) (bool, error)
+ action func(match []string, commitSha string, onDone func()) (bool, error)
}
func (gui *Gui) reflogKey(reflogCommit *commands.Commit) string {
@@ -130,10 +130,17 @@ func (gui *Gui) setUndoReflogKey(key string) {
func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
reflogCommits := gui.State.ReflogCommits
+ // if the index of the previous reflog entry has changed, we need to start from the beginning, because it means there's been user input.
+ startIndex := gui.State.Undo.ReflogIdx
+ if gui.idxOfUndoReflogKey(gui.State.Undo.ReflogKey) != gui.State.Undo.ReflogIdx {
+ gui.State.Undo.UndoCount = 0
+ startIndex = 0
+ }
+
reflogActions := []reflogAction{
{
regexStr: `^checkout: moving from ([\S]+)`,
- action: func(match []string, commitSha string, prevCommitSha string, onDone func()) (bool, error) {
+ action: func(match []string, commitSha string, onDone func()) (bool, error) {
if len(match) <= 1 {
return false, nil
}
@@ -141,19 +148,13 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
},
},
{
- regexStr: `^commit|^rebase -i \(start\)`,
- action: func(match []string, commitSha string, prevCommitSha string, onDone func()) (bool, error) {
- return true, gui.handleHardResetWithAutoStash(prevCommitSha, onDone)
+ regexStr: `^commit|^rebase -i \(start\)|^reset: moving to|^pull`,
+ action: func(match []string, commitSha string, onDone func()) (bool, error) {
+ return true, gui.handleHardResetWithAutoStash(commitSha, onDone)
},
},
}
- // if the index of the previous reflog entry has changed, we need to start from the beginning, because it means there's been user input.
- startIndex := gui.State.Undo.ReflogIdx
- if gui.idxOfUndoReflogKey(gui.State.Undo.ReflogKey) != gui.State.Undo.ReflogIdx {
- startIndex = 0
- }
-
for offsetIdx, reflogCommit := range reflogCommits[startIndex:] {
i := offsetIdx + startIndex
for _, action := range reflogActions {
@@ -167,12 +168,68 @@ func (gui *Gui) reflogUndo(g *gocui.Gui, v *gocui.View) error {
prevCommitSha = reflogCommits[i+1].Sha
}
- nextKey := gui.reflogKey(gui.State.ReflogCommits[i+1])
+ nextKey := gui.reflogKey(reflogCommits[i+1])
onDone := func() {
gui.setUndoReflogKey(nextKey)
+ gui.State.Undo.UndoCount++
+ }
+
+ isMatchingAction, err := action.action(match, prevCommitSha, onDone)
+ if !isMatchingAction {
+ continue
+ }
+
+ return err
+ }
+ }
+
+ return nil
+}
+
+func (gui *Gui) reflogRedo(g *gocui.Gui, v *gocui.View) error {
+ reflogCommits := gui.State.ReflogCommits
+
+ // if the index of the previous reflog entry has changed there is nothing to redo because there's been a user action
+ startIndex := gui.State.Undo.ReflogIdx
+ if gui.idxOfUndoReflogKey(gui.State.Undo.ReflogKey) != gui.State.Undo.ReflogIdx || startIndex == 0 || gui.State.Undo.UndoCount == 0 {
+ return nil
+ }
+
+ reflogActions := []reflogAction{
+ {
+ regexStr: `^checkout: moving from [\S]+ to ([\S]+)`,
+ action: func(match []string, commitSha string, onDone func()) (bool, error) {
+ if len(match) <= 1 {
+ return false, nil
+ }
+ return true, gui.handleCheckoutRef(match[1], handleCheckoutRefOptions{onDone: onDone, waitingStatus: gui.Tr.SLocalize("RedoingStatus")})
+ },
+ },
+ {
+ regexStr: `^commit|^rebase -i \(start\)|^reset: moving to|^pull`,
+ action: func(match []string, commitSha string, onDone func()) (bool, error) {
+ return true, gui.handleHardResetWithAutoStash(commitSha, onDone)
+ },
+ },
+ }
+
+ for i := startIndex - 1; i > 0; i++ {
+ reflogCommit := reflogCommits[i]
+
+ for _, action := range reflogActions {
+ re := regexp.MustCompile(action.regexStr)
+ match := re.FindStringSubmatch(reflogCommit.Name)
+ if len(match) == 0 {
+ continue
+ }
+
+ prevKey := gui.reflogKey(reflogCommits[i-1])
+ onDone := func() {
+ gui.setUndoReflogKey(prevKey)
+ gui.State.Undo.UndoCount--
}
- isMatchingAction, err := action.action(match, reflogCommit.Sha, prevCommitSha, onDone)
+ isMatchingAction, err := action.action(match, reflogCommit.Sha, onDone)
if !isMatchingAction {
continue
}