File tree Expand file tree Collapse file tree 4 files changed +115
-1
lines changed Expand file tree Collapse file tree 4 files changed +115
-1
lines changed Original file line number Diff line number Diff line change @@ -292,7 +292,8 @@ func (self *CommitFilesController) openCopyMenu() error {
292
292
293
293
func (self * CommitFilesController ) checkout (node * filetree.CommitFileNode ) error {
294
294
self .c .LogAction (self .c .Tr .Actions .CheckoutFile )
295
- if err := self .c .Git ().WorkingTree .CheckoutFile (self .context ().GetRef ().RefName (), node .GetPath ()); err != nil {
295
+ _ , to := self .context ().GetFromAndToForDiff ()
296
+ if err := self .c .Git ().WorkingTree .CheckoutFile (to , node .GetPath ()); err != nil {
296
297
return err
297
298
}
298
299
Original file line number Diff line number Diff line change
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
+ })
Original file line number Diff line number Diff line change
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
+ t .FileSystem ().FileContent ("file.txt" , Equals ("three\n " ))
55
+ },
56
+ })
Original file line number Diff line number Diff line change @@ -89,6 +89,8 @@ var tests = []*components.IntegrationTest{
89
89
commit .AmendWhenThereAreConflictsAndContinue ,
90
90
commit .AutoWrapMessage ,
91
91
commit .Checkout ,
92
+ commit .CheckoutFileFromCommit ,
93
+ commit .CheckoutFileFromRangeSelectionOfCommits ,
92
94
commit .Commit ,
93
95
commit .CommitMultiline ,
94
96
commit .CommitSkipHooks ,
You can’t perform that action at this time.
0 commit comments