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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
package gui
import (
"testing"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/stretchr/testify/assert"
)
const diffForTest = `diff --git a/pkg/gui/diff_context_size.go b/pkg/gui/diff_context_size.go
index 0da0a982..742b7dcf 100644
--- a/pkg/gui/diff_context_size.go
+++ b/pkg/gui/diff_context_size.go
@@ -9,12 +9,12 @@ func getRefreshFunction(gui *Gui) func()error {
}
} else if key == MAIN_STAGING_CONTEXT_KEY {
return func() error {
- selectedLine := gui.Views.Secondary.SelectedLineIdx()
+ selectedLine := gui.State.Panels.LineByLine.GetSelectedLineIdx()
return gui.handleRefreshStagingPanel(false, selectedLine)
}
} else if key == MAIN_PATCH_BUILDING_CONTEXT_KEY {
`
func setupGuiForTest(gui *Gui) {
gui.g = &gocui.Gui{}
gui.Views.Main, _ = gui.prepareView("main")
gui.Views.Secondary, _ = gui.prepareView("secondary")
gui.GitCommand.PatchManager = &patch.PatchManager{}
_, _ = gui.refreshLineByLinePanel(diffForTest, "", false, 11)
}
func TestIncreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) {
contexts := []func(gui *Gui) Context{
func(gui *Gui) Context { return gui.State.Contexts.Files },
func(gui *Gui) Context { return gui.State.Contexts.BranchCommits },
func(gui *Gui) Context { return gui.State.Contexts.CommitFiles },
func(gui *Gui) Context { return gui.State.Contexts.Stash },
func(gui *Gui) Context { return gui.State.Contexts.Staging },
func(gui *Gui) Context { return gui.State.Contexts.PatchBuilding },
func(gui *Gui) Context { return gui.State.Contexts.SubCommits },
}
for _, c := range contexts {
gui := NewDummyGui()
context := c(gui)
setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 1
_ = gui.pushContextDirect(context)
_ = gui.IncreaseContextInDiffView()
assert.Equal(t, 2, gui.UserConfig.Git.DiffContextSize, string(context.GetKey()))
}
}
func TestDoesntIncreaseContextInDiffViewInContextWithoutDiff(t *testing.T) {
contexts := []func(gui *Gui) Context{
func(gui *Gui) Context { return gui.State.Contexts.Status },
func(gui *Gui) Context { return gui.State.Contexts.Submodules },
func(gui *Gui) Context { return gui.State.Contexts.Remotes },
func(gui *Gui) Context { return gui.State.Contexts.Normal },
func(gui *Gui) Context { return gui.State.Contexts.ReflogCommits },
func(gui *Gui) Context { return gui.State.Contexts.RemoteBranches },
func(gui *Gui) Context { return gui.State.Contexts.Tags },
func(gui *Gui) Context { return gui.State.Contexts.Merging },
func(gui *Gui) Context { return gui.State.Contexts.CommandLog },
}
for _, c := range contexts {
gui := NewDummyGui()
context := c(gui)
setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 1
_ = gui.pushContextDirect(context)
_ = gui.IncreaseContextInDiffView()
assert.Equal(t, 1, gui.UserConfig.Git.DiffContextSize, string(context.GetKey()))
}
}
func TestDecreasesContextInDiffViewByOneInContextWithDiff(t *testing.T) {
contexts := []func(gui *Gui) Context{
func(gui *Gui) Context { return gui.State.Contexts.Files },
func(gui *Gui) Context { return gui.State.Contexts.BranchCommits },
func(gui *Gui) Context { return gui.State.Contexts.CommitFiles },
func(gui *Gui) Context { return gui.State.Contexts.Stash },
func(gui *Gui) Context { return gui.State.Contexts.Staging },
func(gui *Gui) Context { return gui.State.Contexts.PatchBuilding },
func(gui *Gui) Context { return gui.State.Contexts.SubCommits },
}
for _, c := range contexts {
gui := NewDummyGui()
context := c(gui)
setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 2
_ = gui.pushContextDirect(context)
_ = gui.DecreaseContextInDiffView()
assert.Equal(t, 1, gui.UserConfig.Git.DiffContextSize, string(context.GetKey()))
}
}
func TestDoesntDecreaseContextInDiffViewInContextWithoutDiff(t *testing.T) {
contexts := []func(gui *Gui) Context{
func(gui *Gui) Context { return gui.State.Contexts.Status },
func(gui *Gui) Context { return gui.State.Contexts.Submodules },
func(gui *Gui) Context { return gui.State.Contexts.Remotes },
func(gui *Gui) Context { return gui.State.Contexts.Normal },
func(gui *Gui) Context { return gui.State.Contexts.ReflogCommits },
func(gui *Gui) Context { return gui.State.Contexts.RemoteBranches },
func(gui *Gui) Context { return gui.State.Contexts.Tags },
func(gui *Gui) Context { return gui.State.Contexts.Merging },
func(gui *Gui) Context { return gui.State.Contexts.CommandLog },
}
for _, c := range contexts {
gui := NewDummyGui()
context := c(gui)
setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 2
_ = gui.pushContextDirect(context)
_ = gui.DecreaseContextInDiffView()
assert.Equal(t, 2, gui.UserConfig.Git.DiffContextSize, string(context.GetKey()))
}
}
func TestDoesntIncreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *testing.T) {
gui := NewDummyGui()
setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 2
_ = gui.pushContextDirect(gui.State.Contexts.CommitFiles)
gui.GitCommand.PatchManager.Start("from", "to", false, false)
errorCount := 0
gui.PopupHandler = &TestPopupHandler{
onError: func(message string) error {
assert.Equal(t, gui.Tr.CantChangeContextSizeError, message)
errorCount += 1
return nil
},
}
_ = gui.IncreaseContextInDiffView()
assert.Equal(t, 1, errorCount)
assert.Equal(t, 2, gui.UserConfig.Git.DiffContextSize)
}
func TestDoesntDecreaseContextInDiffViewInContextWhenInPatchBuildingMode(t *testing.T) {
gui := NewDummyGui()
setupGuiForTest(gui)
gui.UserConfig.Git.DiffContextSize = 2
_ = gui.pushContextDirect(gui.State.Contexts.CommitFiles)
gui.GitCommand.PatchManager.Start("from", "to"
|