summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go
blob: 74dd34b3e9176cf35eb32eb0badf34972ca5c3c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package patch_building

import (
	"github.com/jesseduffield/lazygit/pkg/config"
	. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var ApplyInReverseWithConflict = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Apply a custom patch in reverse, resulting in a conflict",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFileAndAdd("file1", "file1 content\n")
		shell.CreateFileAndAdd("file2", "file2 content\n")
		shell.Commit("first commit")
		shell.UpdateFileAndAdd("file1", "file1 content\nmore file1 content\n")
		shell.UpdateFileAndAdd("file2", "file2 content\nmore file2 content\n")
		shell.Commit("second commit")
		shell.UpdateFileAndAdd("file1", "file1 content\nmore file1 content\neven more file1\n")
		shell.Commit("third commit")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			Focus().
			Lines(
				Contains("third commit").IsSelected(),
				Contains("second commit"),
				Contains("first commit"),
			).
			NavigateToLine(Contains("second commit")).
			PressEnter()

		t.Views().CommitFiles().
			IsFocused().
			Lines(
				Contains("M").Contains("file1").IsSelected(),
				Contains("M").Contains("file2"),
			).
			// Add both files to the patch; the first will conflict, the second won't
			PressPrimaryAction().
			Tap(func() {
				t.Views().Information().Content(Contains("Building patch"))

				t.Views().PatchBuildingSecondary().Content(
					Contains("+more file1 content"))
			}).
			SelectNextItem().
			PressPrimaryAction()

		t.Views().PatchBuildingSecondary().Content(
			Contains("+more file1 content").Contains("+more file2 content"))

		t.Common().SelectPatchOption(Contains("Apply patch in reverse"))

		t.ExpectPopup().Alert().
			Title(Equals("Error")).
			Content(Contains("Applied patch to 'file1' with conflicts.")).
			Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("UU").Contains("file1").IsSelected(),
			).
			PressPrimaryAction()

		t.Views().MergeConflicts().
			IsFocused().
			ContainsLines(
				Contains("file1 content"),
				Contains("<<<<<<< ours").IsSelected(),
				Contains("more file1 content").IsSelected(),
				Contains("even more file1").IsSelected(),
				Contains("=======").IsSelected(),
				Contains(">>>>>>> theirs"),
			).
			SelectNextItem().
			PressPrimaryAction()

		t.Views().Files().
			Focus().
			Lines(
				Contains("M").Contains("file1").IsSelected(),
				Contains("M").Contains("file2"),
			)

		t.Views().Main().
			ContainsLines(
				Contains(" file1 content"),
				Contains("-more file1 content"),
				Contains("-even more file1"),
			)
	},
})