Skip to content

Commit 65bd0ab

Browse files
committed
migrate undo test
1 parent 93b9e1b commit 65bd0ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+95
-139
lines changed

pkg/gui/controllers/undo_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ func (self *UndoController) parseReflogForActions(onUserAction func(counter int,
195195
counter++
196196
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^\[lazygit redo\]`); ok {
197197
counter--
198-
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase -i \(abort\)|^rebase -i \(finish\)`); ok {
198+
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(abort\)|^rebase (-i )?\(finish\)`); ok {
199199
rebaseFinishCommitSha = reflogCommit.Sha
200200
} else if ok, match := utils.FindStringSubmatch(reflogCommit.Name, `^checkout: moving from ([\S]+) to ([\S]+)`); ok {
201201
action = &reflogAction{kind: CHECKOUT, from: match[1], to: match[2]}
202202
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^commit|^reset: moving to|^pull`); ok {
203203
action = &reflogAction{kind: COMMIT, from: prevCommitSha, to: reflogCommit.Sha}
204-
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase -i \(start\)`); ok {
204+
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(start\)`); ok {
205205
// if we're here then we must be currently inside an interactive rebase
206206
action = &reflogAction{kind: CURRENT_REBASE, from: prevCommitSha}
207207
}
208-
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase -i \(start\)`); ok {
208+
} else if ok, _ := utils.FindStringSubmatch(reflogCommit.Name, `^rebase (-i )?\(start\)`); ok {
209209
action = &reflogAction{kind: REBASE, from: prevCommitSha, to: rebaseFinishCommitSha}
210210
rebaseFinishCommitSha = ""
211211
}

pkg/integration/tests/tests_gen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/jesseduffield/lazygit/pkg/integration/tests/stash"
2121
"github.com/jesseduffield/lazygit/pkg/integration/tests/submodule"
2222
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
23+
"github.com/jesseduffield/lazygit/pkg/integration/tests/undo"
2324
)
2425

2526
var tests = []*components.IntegrationTest{
@@ -83,4 +84,5 @@ var tests = []*components.IntegrationTest{
8384
sync.Pull,
8485
sync.PullAndSetUpstream,
8586
sync.RenameBranchAndPull,
87+
undo.UndoDrop,
8688
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package undo
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var UndoDrop = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Drop some commits and then undo/redo the actions",
10+
ExtraCmdArgs: "",
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.EmptyCommit("one")
15+
shell.EmptyCommit("two")
16+
shell.EmptyCommit("three")
17+
shell.EmptyCommit("four")
18+
},
19+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
20+
confirmCommitDrop := func() {
21+
t.ExpectPopup().Confirmation().
22+
Title(Equals("Delete Commit")).
23+
Content(Equals("Are you sure you want to delete this commit?")).
24+
Confirm()
25+
}
26+
27+
confirmUndo := func() {
28+
t.ExpectPopup().Confirmation().
29+
Title(Equals("Undo")).
30+
Content(MatchesRegexp(`Are you sure you want to hard reset to '.*'\? An auto-stash will be performed if necessary\.`)).
31+
Confirm()
32+
}
33+
34+
confirmRedo := func() {
35+
t.ExpectPopup().Confirmation().
36+
Title(Equals("Redo")).
37+
Content(MatchesRegexp(`Are you sure you want to hard reset to '.*'\? An auto-stash will be performed if necessary\.`)).
38+
Confirm()
39+
}
40+
41+
t.Views().Commits().Focus().
42+
Lines(
43+
Contains("four").IsSelected(),
44+
Contains("three"),
45+
Contains("two"),
46+
Contains("one"),
47+
).
48+
Press(keys.Universal.Remove).
49+
Tap(confirmCommitDrop).
50+
Lines(
51+
Contains("three").IsSelected(),
52+
Contains("two"),
53+
Contains("one"),
54+
).
55+
Press(keys.Universal.Remove).
56+
Tap(confirmCommitDrop).
57+
Lines(
58+
Contains("two").IsSelected(),
59+
Contains("one"),
60+
).
61+
Press(keys.Universal.Undo).
62+
Tap(confirmUndo).
63+
Lines(
64+
Contains("three").IsSelected(),
65+
Contains("two"),
66+
Contains("one"),
67+
).
68+
Press(keys.Universal.Undo).
69+
Tap(confirmUndo).
70+
Lines(
71+
Contains("four").IsSelected(),
72+
Contains("three"),
73+
Contains("two"),
74+
Contains("one"),
75+
).
76+
Press(keys.Universal.Redo).
77+
Tap(confirmRedo).
78+
Lines(
79+
Contains("three").IsSelected(),
80+
Contains("two"),
81+
Contains("one"),
82+
).
83+
Press(keys.Universal.Redo).
84+
Tap(confirmRedo).
85+
Lines(
86+
Contains("two").IsSelected(),
87+
Contains("one"),
88+
)
89+
},
90+
})

test/integration/undo/expected/repo/.git_keep/COMMIT_EDITMSG

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/integration/undo/expected/repo/.git_keep/FETCH_HEAD

Whitespace-only changes.

test/integration/undo/expected/repo/.git_keep/HEAD

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/integration/undo/expected/repo/.git_keep/ORIG_HEAD

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/integration/undo/expected/repo/.git_keep/config

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/integration/undo/expected/repo/.git_keep/description

Lines changed: 0 additions & 1 deletion
This file was deleted.
-353 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)