Skip to content

Commit 1c5fe8f

Browse files
committed
Add a test demonstrating the problem
When pressing `e` on line 5 in a diff of an older commit, we expect it to take us to line 5 in that file. But we end up on line 2, because the file had further changes both in newer commits, and in the unstaged changes of the working copy.
1 parent 49ca7f6 commit 1c5fe8f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 EditLineInPatchBuildingPanel = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Edit a line in the patch building panel; make sure we end up on the right line",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
config.GetUserConfig().OS.EditAtLine = "echo {{filename}}:{{line}} > edit-command"
14+
},
15+
SetupRepo: func(shell *Shell) {
16+
shell.CreateFileAndAdd("file.txt", "4\n5\n6\n")
17+
shell.Commit("01")
18+
shell.UpdateFileAndAdd("file.txt", "1\n2a\n2b\n3\n4\n5\n6\n")
19+
shell.Commit("02")
20+
shell.UpdateFile("file.txt", "1\n2\n3\n4\n5\n6\n")
21+
},
22+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
23+
t.Views().Commits().
24+
Focus().
25+
Lines(
26+
Contains("02").IsSelected(),
27+
Contains("01"),
28+
).
29+
Press(keys.Universal.NextItem).
30+
PressEnter()
31+
32+
t.Views().CommitFiles().
33+
IsFocused().
34+
Lines(
35+
Contains("A file.txt").IsSelected(),
36+
).
37+
PressEnter()
38+
39+
t.Views().PatchBuilding().
40+
IsFocused().
41+
Content(Contains("+4\n+5\n+6")).
42+
NavigateToLine(Contains("+5")).
43+
Press(keys.Universal.Edit)
44+
45+
/* EXPECTED:
46+
t.FileSystem().FileContent("edit-command", Contains("file.txt:5\n"))
47+
ACTUAL: */
48+
t.FileSystem().FileContent("edit-command", Contains("file.txt:2\n"))
49+
},
50+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ var tests = []*components.IntegrationTest{
257257
patch_building.Apply,
258258
patch_building.ApplyInReverse,
259259
patch_building.ApplyInReverseWithConflict,
260+
patch_building.EditLineInPatchBuildingPanel,
260261
patch_building.MoveRangeToIndex,
261262
patch_building.MoveToEarlierCommit,
262263
patch_building.MoveToEarlierCommitFromAddedFile,

0 commit comments

Comments
 (0)