Skip to content

Commit ac7d8ad

Browse files
committed
Add test for checking out a file from a commit
This works, we just didn't have a test for it.
1 parent 5038fa2 commit ac7d8ad

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 CheckoutFileFromCommit = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Checkout a file from a commit",
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+
Tap(func() {
34+
t.Views().Main().ContainsLines(
35+
Contains("-two"),
36+
Contains("+three"),
37+
)
38+
}).
39+
PressEnter()
40+
41+
t.Views().CommitFiles().
42+
IsFocused().
43+
Lines(
44+
Equals("M file.txt"),
45+
).
46+
Press(keys.CommitFiles.CheckoutCommitFile)
47+
48+
t.Views().Files().
49+
Lines(
50+
Equals("M file.txt"),
51+
)
52+
53+
t.FileSystem().FileContent("file.txt", Equals("three\n"))
54+
},
55+
})

pkg/integration/tests/test_list.go

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

0 commit comments

Comments
 (0)