Skip to content

Commit 823aa64

Browse files
committed
Add test for moving patch to index when there's a modified file
This is functionality that works already, we only add the test for more complete test coverage. However, there's a detail problem, and the test demonstrates this: we keep the stash even if there was no conflict. We'll fix this next.
1 parent 00d043d commit 823aa64

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 MoveToIndexWithModifiedFile = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Move a patch from a commit to the index, with a modified file in the working tree that conflicts with the patch",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.CreateFileAndAdd("file1", "1\n2\n3\n4\n")
15+
shell.Commit("first commit")
16+
shell.UpdateFileAndAdd("file1", "11\n2\n3\n4\n")
17+
shell.Commit("second commit")
18+
shell.UpdateFile("file1", "111\n2\n3\n4\n")
19+
},
20+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
21+
t.Views().Commits().
22+
Focus().
23+
Lines(
24+
Contains("second commit").IsSelected(),
25+
Contains("first commit"),
26+
).
27+
PressEnter()
28+
29+
t.Views().CommitFiles().
30+
IsFocused().
31+
Lines(
32+
Equals("M file1"),
33+
).
34+
PressPrimaryAction()
35+
36+
t.Views().Information().Content(Contains("Building patch"))
37+
38+
t.Views().Secondary().Content(Contains("-1\n+11"))
39+
40+
t.Common().SelectPatchOption(Contains("Move patch out into index"))
41+
42+
t.ExpectPopup().Confirmation().Title(Equals("Must stash")).
43+
Content(Contains("Pulling a patch out into the index requires stashing and unstashing your changes.")).
44+
Confirm()
45+
46+
t.Views().Files().
47+
Focus().
48+
Lines(
49+
Equals("MM file1"),
50+
)
51+
52+
t.Views().Main().
53+
Content(Contains("-11\n+111\n"))
54+
t.Views().Secondary().
55+
Content(Contains("-1\n+11\n"))
56+
57+
/* EXPECTED:
58+
t.Views().Stash().IsEmpty()
59+
ACTUAL: */
60+
t.Views().Stash().Lines(
61+
Contains("Auto-stashing changes"),
62+
)
63+
},
64+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ var tests = []*components.IntegrationTest{
310310
patch_building.MoveToIndexPartOfAdjacentAddedLines,
311311
patch_building.MoveToIndexPartial,
312312
patch_building.MoveToIndexWithConflict,
313+
patch_building.MoveToIndexWithModifiedFile,
313314
patch_building.MoveToIndexWorksEvenIfNoprefixIsSet,
314315
patch_building.MoveToLaterCommit,
315316
patch_building.MoveToLaterCommitPartialHunk,

0 commit comments

Comments
 (0)