Skip to content

Commit c440a20

Browse files
committed
Add tests for applying a patch when there's a modified file
The tests show that this currently fails with the confusing error message "does not match index", regardless of whether the patch conflicts with the modifications or not. We'll improve this in the next commit. I don't bother adding tests for reverting a patch, as the code is basically the same as for apply.
1 parent 32bd9e6 commit c440a20

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 ApplyWithModifiedFileConflict = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Apply a custom patch, 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.NewBranch("branch-a")
15+
shell.CreateFileAndAdd("file1", "1\n2\n3\n")
16+
shell.Commit("first commit")
17+
18+
shell.NewBranch("branch-b")
19+
shell.UpdateFileAndAdd("file1", "11\n2\n3\n")
20+
shell.Commit("update")
21+
22+
shell.Checkout("branch-a")
23+
shell.UpdateFile("file1", "111\n2\n3\n")
24+
},
25+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
26+
t.Views().Branches().
27+
Focus().
28+
Lines(
29+
Contains("branch-a").IsSelected(),
30+
Contains("branch-b"),
31+
).
32+
Press(keys.Universal.NextItem).
33+
PressEnter()
34+
35+
t.Views().SubCommits().
36+
IsFocused().
37+
Lines(
38+
Contains("update").IsSelected(),
39+
Contains("first commit"),
40+
).
41+
PressEnter()
42+
43+
t.Views().CommitFiles().
44+
IsFocused().
45+
Lines(
46+
Equals("M file1").IsSelected(),
47+
).
48+
PressPrimaryAction()
49+
50+
t.Views().Information().Content(Contains("Building patch"))
51+
52+
t.Views().Secondary().Content(Contains("-1\n+11\n"))
53+
54+
t.Common().SelectPatchOption(MatchesRegexp(`Apply patch$`))
55+
56+
t.ExpectPopup().Alert().Title(Equals("Error")).
57+
Content(Equals("error: file1: does not match index")).
58+
Confirm()
59+
},
60+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 ApplyWithModifiedFileNoConflict = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Apply a custom patch, with a modified file in the working tree that does not conflict with the patch",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.NewBranch("branch-a")
15+
shell.CreateFileAndAdd("file1", "1\n2\n3\n")
16+
shell.Commit("first commit")
17+
18+
shell.NewBranch("branch-b")
19+
shell.UpdateFileAndAdd("file1", "1\n2\n3\n4\n")
20+
shell.Commit("update")
21+
22+
shell.Checkout("branch-a")
23+
shell.UpdateFile("file1", "11\n2\n3\n")
24+
},
25+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
26+
t.Views().Branches().
27+
Focus().
28+
Lines(
29+
Contains("branch-a").IsSelected(),
30+
Contains("branch-b"),
31+
).
32+
Press(keys.Universal.NextItem).
33+
PressEnter()
34+
35+
t.Views().SubCommits().
36+
IsFocused().
37+
Lines(
38+
Contains("update").IsSelected(),
39+
Contains("first commit"),
40+
).
41+
PressEnter()
42+
43+
t.Views().CommitFiles().
44+
IsFocused().
45+
Lines(
46+
Equals("M file1").IsSelected(),
47+
).
48+
PressPrimaryAction()
49+
50+
t.Views().Information().Content(Contains("Building patch"))
51+
52+
t.Views().Secondary().Content(Contains("3\n+4"))
53+
54+
t.Common().SelectPatchOption(MatchesRegexp(`Apply patch$`))
55+
56+
t.ExpectPopup().Alert().Title(Equals("Error")).
57+
Content(Equals("error: file1: does not match index")).
58+
Confirm()
59+
},
60+
})

pkg/integration/tests/test_list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ var tests = []*components.IntegrationTest{
300300
patch_building.Apply,
301301
patch_building.ApplyInReverse,
302302
patch_building.ApplyInReverseWithConflict,
303+
patch_building.ApplyWithModifiedFileConflict,
304+
patch_building.ApplyWithModifiedFileNoConflict,
303305
patch_building.EditLineInPatchBuildingPanel,
304306
patch_building.MoveRangeToIndex,
305307
patch_building.MoveToEarlierCommit,

0 commit comments

Comments
 (0)