Skip to content

Commit 8a16f24

Browse files
committed
Add test for moving a patch from a deleted file to a new commit
This currently works, we add it as a regression test to make sure we don't break it. It is an interesting test because it turns the deletion of the file in the moved-from commit into a modification.
1 parent e2b4d9c commit 8a16f24

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package patch_building
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var MoveToNewCommitFromDeletedFile = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Move a patch from a file that was deleted in a commit to a new commit",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.CreateFileAndAdd("file1", "1st line\n2nd line\n3rd line\n")
15+
shell.Commit("first commit")
16+
shell.DeleteFileAndAdd("file1")
17+
shell.Commit("commit to move from")
18+
},
19+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
20+
t.Views().Commits().
21+
Focus().
22+
Lines(
23+
Contains("commit to move from").IsSelected(),
24+
Contains("first commit"),
25+
).
26+
PressEnter()
27+
28+
t.Views().CommitFiles().
29+
IsFocused().
30+
Lines(
31+
Contains("D file1").IsSelected(),
32+
).
33+
PressEnter()
34+
35+
t.Views().PatchBuilding().
36+
IsFocused().
37+
SelectNextItem().
38+
PressPrimaryAction()
39+
40+
t.Views().Information().Content(Contains("Building patch"))
41+
42+
t.Common().SelectPatchOption(Contains("Move patch into new commit"))
43+
44+
t.ExpectPopup().CommitMessagePanel().
45+
InitialText(Equals("")).
46+
Type("new commit").Confirm()
47+
48+
t.Views().Commits().
49+
IsFocused().
50+
Lines(
51+
Contains("new commit").IsSelected(),
52+
Contains("commit to move from"),
53+
Contains("first commit"),
54+
).
55+
PressEnter()
56+
57+
t.Views().CommitFiles().
58+
IsFocused().
59+
Lines(
60+
Contains("D file1").IsSelected(),
61+
).
62+
Tap(func() {
63+
t.Views().Main().ContainsLines(
64+
Equals("-2nd line"),
65+
)
66+
}).
67+
PressEscape()
68+
69+
t.Views().Commits().
70+
IsFocused().
71+
NavigateToLine(Contains("commit to move from")).
72+
PressEnter()
73+
74+
t.Views().CommitFiles().
75+
IsFocused().
76+
Lines(
77+
// In the original commit the file is no longer deleted, but modified
78+
Contains("M file1").IsSelected(),
79+
).
80+
Tap(func() {
81+
t.Views().Main().ContainsLines(
82+
Equals("-1st line"),
83+
Equals(" 2nd line"),
84+
Equals("-3rd line"),
85+
)
86+
})
87+
},
88+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ var tests = []*components.IntegrationTest{
238238
patch_building.MoveToLaterCommit,
239239
patch_building.MoveToLaterCommitPartialHunk,
240240
patch_building.MoveToNewCommit,
241+
patch_building.MoveToNewCommitFromDeletedFile,
241242
patch_building.MoveToNewCommitPartialHunk,
242243
patch_building.RemoveFromCommit,
243244
patch_building.ResetWithEscape,

0 commit comments

Comments
 (0)