summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/staging/stage_hunks.go
blob: c2f85661aa2a46ade9c7af9753db765b26f0b268 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package staging

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

var StageHunks = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Stage and unstage various hunks of a file in the staging panel",
	ExtraCmdArgs: "",
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		// need to be working with a few lines so that git perceives it as two separate hunks
		shell.CreateFileAndAdd("file1", "1a\n2a\n3a\n4a\n5a\n6a\n7a\n8a\n9a\n10a\n11a\n12a\n13a\n14a\n15a")
		shell.Commit("one")

		shell.UpdateFile("file1", "1a\n2a\n3b\n4a\n5a\n6a\n7a\n8a\n9a\n10a\n11a\n12a\n13b\n14a\n15a")

		// hunk looks like:
		// diff --git a/file1 b/file1
		// index 3653080..a6388b6 100644
		// --- a/file1
		// +++ b/file1
		// @@ -1,6 +1,6 @@
		//  1a
		//  2a
		// -3a
		// +3b
		//  4a
		//  5a
		//  6a
		// @@ -10,6 +10,6 @@
		//  10a
		//  11a
		//  12a
		// -13a
		// +13b
		//  14a
		//  15a
		// \ No newline at end of file
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file1").IsSelected(),
			).
			PressEnter()

		t.Views().Staging().
			IsFocused().
			SelectedLines(
				Contains("-3a"),
			).
			Press(keys.Universal.NextBlock).
			SelectedLines(
				Contains("-13a"),
			).
			Press(keys.Main.ToggleSelectHunk).
			SelectedLines(
				Contains("@@ -10,6 +10,6 @@"),
				Contains(" 10a"),
				Contains(" 11a"),
				Contains(" 12a"),
				Contains("-13a"),
				Contains("+13b"),
				Contains(" 14a"),
				Contains(" 15a"),
				Contains(`\ No newline at end of file`),
			).
			// when in hunk mode, pressing up/down moves us up/down by a hunk
			SelectPreviousItem().
			SelectedLines(
				Contains(`@@ -1,6 +1,6 @@`),
				Contains(` 1a`),
				Contains(` 2a`),
				Contains(`-3a`),
				Contains(`+3b`),
				Contains(` 4a`),
				Contains(` 5a`),
				Contains(` 6a`),
			).
			SelectNextItem().
			SelectedLines(
				Contains("@@ -10,6 +10,6 @@"),
				Contains(" 10a"),
				Contains(" 11a"),
				Contains(" 12a"),
				Contains("-13a"),
				Contains("+13b"),
				Contains(" 14a"),
				Contains(" 15a"),
				Contains(`\ No newline at end of file`),
			).
			// stage the second hunk
			PressPrimaryAction().
			ContainsLines(
				Contains("-3a"),
				Contains("+3b"),
			).
			Tap(func() {
				t.Views().StagingSecondary().
					ContainsLines(
						Contains("-13a"),
						Contains("+13b"),
					)
			}).
			Press(keys.Universal.TogglePanel)

		t.Views().StagingSecondary().
			IsFocused().
			// after toggling panel, we're back to only having selected a single line
			SelectedLines(
				Contains("-13a"),
			).
			PressPrimaryAction().
			SelectedLines(
				Contains("+13b"),
			).
			PressPrimaryAction().
			IsEmpty()

		t.Views().Staging().
			IsFocused().
			SelectedLines(
				Contains("-3a"),
			).
			Press(keys.Main.ToggleSelectHunk).
			SelectedLines(
				Contains(`@@ -1,6 +1,6 @@`),
				Contains(` 1a`),
				Contains(` 2a`),
				Contains(`-3a`),
				Contains(`+3b`),
				Contains(` 4a`),
				Contains(` 5a`),
				Contains(` 6a`),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.Actions().ConfirmDiscardLines()
			}).
			Content(DoesNotContain("-3a").DoesNotContain("+3b")).
			SelectedLines(
				Contains("@@ -10,6 +10,6 @@"),
				Contains(" 10a"),
				Contains(" 11a"),
				Contains(" 12a"),
				Contains("-13a"),
				Contains("+13b"),
				Contains(" 14a"),
				Contains(" 15a"),
				Contains(`\ No newline at end of file`),
			)
	},
})