summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/diff/diff_and_apply_patch.go
blob: 65bb27ebdb37551aa6757b29e4d0d9e2fd28d09b (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
package diff

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

var DiffAndApplyPatch = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Create a patch from the diff between two branches and apply the patch.",
	ExtraCmdArgs: "",
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("branch-a")
		shell.CreateFileAndAdd("file1", "first line\n")
		shell.Commit("first commit")

		shell.NewBranch("branch-b")
		shell.UpdateFileAndAdd("file1", "first line\nsecond line\n")
		shell.Commit("update")

		shell.Checkout("branch-a")
	},
	Run: func(shell *Shell, input *Input, keys config.KeybindingConfig) {
		input.Views().Branches().
			Focus().
			Lines(
				Contains("branch-a"),
				Contains("branch-b"),
			).
			Press(keys.Universal.DiffingMenu)

		input.ExpectMenu().Title(Equals("Diffing")).Select(Equals("diff branch-a")).Confirm()

		input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-a"))

		input.Views().Branches().
			IsFocused().
			SelectNextItem().
			Tap(func() {
				input.Views().Information().Content(Contains("showing output for: git diff branch-a branch-b"))
				input.Views().Main().Content(Contains("+second line"))
			}).
			PressEnter()

		input.Views().SubCommits().
			IsFocused().
			SelectedLine(Contains("update")).
			Tap(func() {
				input.Views().Main().Content(Contains("+second line"))
			}).
			PressEnter()

		input.Views().CommitFiles().
			IsFocused().
			SelectedLine(Contains("file1")).
			Tap(func() {
				input.Views().Main().Content(Contains("+second line"))
			}).
			PressPrimaryAction(). // add the file to the patch
			Press(keys.Universal.DiffingMenu).
			Tap(func() {
				input.ExpectMenu().Title(Equals("Diffing")).Select(Contains("exit diff mode")).Confirm()

				input.Views().Information().Content(DoesNotContain("building patch"))
			}).
			Press(keys.Universal.CreatePatchOptionsMenu)

		// adding the regex '$' here to distinguish the menu item from the 'apply patch in reverse' item
		input.ExpectMenu().Title(Equals("Patch Options")).Select(MatchesRegexp("apply patch$")).Confirm()

		input.Views().Files().
			Focus().
			SelectedLine(Contains("file1"))

		input.Views().Main().Content(Contains("+second line"))
	},
})