Skip to content

Commit 61c56c7

Browse files
committed
Add test for checking out a file from a range selection of commits
The test shows a misbehavior: even though the diff shows "-one" and "+three", meaning that "three" is the state we want to check out, we get "one". The reason is that the checkout file command doesn't pay attention to range selections, it only looks at the "moving end" of the range. Had we created the range by selecting "two" and then pressed shift-up to "three", we would have gotten the expected result.
1 parent ac7d8ad commit 61c56c7

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package commit
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var CheckoutFileFromRangeSelectionOfCommits = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Checkout a file from a range selection of commits",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {},
13+
SetupRepo: func(shell *Shell) {
14+
shell.CreateFileAndAdd("file.txt", "one\n")
15+
shell.Commit("one")
16+
shell.CreateFileAndAdd("file.txt", "two\n")
17+
shell.Commit("two")
18+
shell.CreateFileAndAdd("file.txt", "three\n")
19+
shell.Commit("three")
20+
shell.CreateFileAndAdd("file.txt", "four\n")
21+
shell.Commit("four")
22+
},
23+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
24+
t.Views().Commits().
25+
Focus().
26+
Lines(
27+
Contains("four").IsSelected(),
28+
Contains("three"),
29+
Contains("two"),
30+
Contains("one"),
31+
).
32+
NavigateToLine(Contains("three")).
33+
Press(keys.Universal.RangeSelectDown).
34+
Tap(func() {
35+
t.Views().Main().ContainsLines(
36+
Contains("-one"),
37+
Contains("+three"),
38+
)
39+
}).
40+
PressEnter()
41+
42+
t.Views().CommitFiles().
43+
IsFocused().
44+
Lines(
45+
Equals("M file.txt"),
46+
).
47+
Press(keys.CommitFiles.CheckoutCommitFile)
48+
49+
t.Views().Files().
50+
Lines(
51+
Equals("M file.txt"),
52+
)
53+
54+
/* EXPECTED:
55+
t.FileSystem().FileContent("file.txt", Equals("three\n"))
56+
ACTUAL: */
57+
t.FileSystem().FileContent("file.txt", Equals("two\n"))
58+
},
59+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ var tests = []*components.IntegrationTest{
9090
commit.AutoWrapMessage,
9191
commit.Checkout,
9292
commit.CheckoutFileFromCommit,
93+
commit.CheckoutFileFromRangeSelectionOfCommits,
9394
commit.Commit,
9495
commit.CommitMultiline,
9596
commit.CommitSkipHooks,

0 commit comments

Comments
 (0)