@@ -10,6 +10,7 @@ import (
10
10
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
11
11
"github.com/jesseduffield/lazygit/pkg/config"
12
12
"github.com/jesseduffield/lazygit/pkg/utils"
13
+ "github.com/samber/lo"
13
14
"github.com/stefanhaller/git-todo-parser/todo"
14
15
"github.com/stretchr/testify/assert"
15
16
)
@@ -27,13 +28,13 @@ var singleCommitOutput = strings.Replace(`0eea75e8c631fba6b58135697835d58ba4c18d
27
28
28
29
func TestGetCommits (t * testing.T ) {
29
30
type scenario struct {
30
- testName string
31
- runner * oscommands.FakeCmdObjRunner
32
- expectedCommits []* models.Commit
33
- expectedError error
34
- logOrder string
35
- opts GetCommitsOptions
36
- mainBranches []string
31
+ testName string
32
+ runner * oscommands.FakeCmdObjRunner
33
+ expectedCommitOpts []models.NewCommitOpts
34
+ expectedError error
35
+ logOrder string
36
+ opts GetCommitsOptions
37
+ mainBranches []string
37
38
}
38
39
39
40
scenarios := []scenario {
@@ -45,8 +46,8 @@ func TestGetCommits(t *testing.T) {
45
46
ExpectGitArgs ([]string {"merge-base" , "mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164" , nil ).
46
47
ExpectGitArgs ([]string {"log" , "HEAD" , "--topo-order" , "--oneline" , "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, "" , nil ),
47
48
48
- expectedCommits : []* models.Commit {},
49
- expectedError : nil ,
49
+ expectedCommitOpts : []models.NewCommitOpts {},
50
+ expectedError : nil ,
50
51
},
51
52
{
52
53
testName : "should use proper upstream name for branch" ,
@@ -56,8 +57,8 @@ func TestGetCommits(t *testing.T) {
56
57
ExpectGitArgs ([]string {"merge-base" , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164" , nil ).
57
58
ExpectGitArgs ([]string {"log" , "refs/heads/mybranch" , "--topo-order" , "--oneline" , "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, "" , nil ),
58
59
59
- expectedCommits : []* models.Commit {},
60
- expectedError : nil ,
60
+ expectedCommitOpts : []models.NewCommitOpts {},
61
+ expectedError : nil ,
61
62
},
62
63
{
63
64
testName : "should return commits if they are present" ,
@@ -79,7 +80,7 @@ func TestGetCommits(t *testing.T) {
79
80
// here it's seeing where our branch diverged from the master branch so that we can mark that commit and parent commits as 'merged'
80
81
ExpectGitArgs ([]string {"merge-base" , "HEAD" , "refs/remotes/origin/master" , "refs/remotes/origin/main" }, "26c07b1ab33860a1a7591a0638f9925ccf497ffa" , nil ),
81
82
82
- expectedCommits : []* models.Commit {
83
+ expectedCommitOpts : []models.NewCommitOpts {
83
84
{
84
85
Hash : "0eea75e8c631fba6b58135697835d58ba4c18dbc" ,
85
86
Name : "better typing for rebase mode" ,
@@ -213,7 +214,7 @@ func TestGetCommits(t *testing.T) {
213
214
ExpectGitArgs ([]string {"rev-parse" , "--verify" , "--quiet" , "refs/remotes/origin/main" }, "" , errors .New ("error" )).
214
215
ExpectGitArgs ([]string {"rev-parse" , "--verify" , "--quiet" , "refs/heads/main" }, "" , errors .New ("error" )),
215
216
216
- expectedCommits : []* models.Commit {
217
+ expectedCommitOpts : []models.NewCommitOpts {
217
218
{
218
219
Hash : "0eea75e8c631fba6b58135697835d58ba4c18dbc" ,
219
220
Name : "better typing for rebase mode" ,
@@ -251,7 +252,7 @@ func TestGetCommits(t *testing.T) {
251
252
// here it's seeing where our branch diverged from the master branch so that we can mark that commit and parent commits as 'merged'
252
253
ExpectGitArgs ([]string {"merge-base" , "HEAD" , "refs/remotes/origin/master" , "refs/remotes/origin/develop" , "refs/remotes/origin/1.0-hotfixes" }, "26c07b1ab33860a1a7591a0638f9925ccf497ffa" , nil ),
253
254
254
- expectedCommits : []* models.Commit {
255
+ expectedCommitOpts : []models.NewCommitOpts {
255
256
{
256
257
Hash : "0eea75e8c631fba6b58135697835d58ba4c18dbc" ,
257
258
Name : "better typing for rebase mode" ,
@@ -277,8 +278,8 @@ func TestGetCommits(t *testing.T) {
277
278
ExpectGitArgs ([]string {"merge-base" , "mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164" , nil ).
278
279
ExpectGitArgs ([]string {"log" , "HEAD" , "--oneline" , "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, "" , nil ),
279
280
280
- expectedCommits : []* models.Commit {},
281
- expectedError : nil ,
281
+ expectedCommitOpts : []models.NewCommitOpts {},
282
+ expectedError : nil ,
282
283
},
283
284
{
284
285
testName : "should set filter path" ,
@@ -288,8 +289,8 @@ func TestGetCommits(t *testing.T) {
288
289
ExpectGitArgs ([]string {"merge-base" , "mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164" , nil ).
289
290
ExpectGitArgs ([]string {"log" , "HEAD" , "--oneline" , "--pretty=format:%H%x00%at%x00%aN%x00%ae%x00%D%x00%p%x00%m%x00%s" , "--abbrev=40" , "--follow" , "--no-show-signature" , "--" , "src" }, "" , nil ),
290
291
291
- expectedCommits : []* models.Commit {},
292
- expectedError : nil ,
292
+ expectedCommitOpts : []models.NewCommitOpts {},
293
+ expectedError : nil ,
293
294
},
294
295
}
295
296
@@ -318,7 +319,9 @@ func TestGetCommits(t *testing.T) {
318
319
opts .MainBranches = NewMainBranches (common , cmd )
319
320
commits , err := builder .GetCommits (opts )
320
321
321
- assert .Equal (t , scenario .expectedCommits , commits )
322
+ expectedCommits := lo .Map (scenario .expectedCommitOpts ,
323
+ func (opts models.NewCommitOpts , _ int ) * models.Commit { return models .NewCommit (opts ) })
324
+ assert .Equal (t , expectedCommits , commits )
322
325
assert .Equal (t , scenario .expectedError , err )
323
326
324
327
scenario .runner .CheckForMissingCalls ()
@@ -356,11 +359,11 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
356
359
},
357
360
},
358
361
amendFileExists : false ,
359
- expectedResult : & models.Commit {
362
+ expectedResult : models .NewCommit (models. NewCommitOpts {
360
363
Hash : "fa1afe1" ,
361
364
Action : todo .Pick ,
362
365
Status : models .StatusConflicted ,
363
- },
366
+ }) ,
364
367
},
365
368
{
366
369
testName : "last command was 'break'" ,
@@ -457,11 +460,11 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
457
460
},
458
461
},
459
462
amendFileExists : false ,
460
- expectedResult : & models.Commit {
463
+ expectedResult : models .NewCommit (models. NewCommitOpts {
461
464
Hash : "fa1afe1" ,
462
465
Action : todo .Pick ,
463
466
Status : models .StatusConflicted ,
464
- },
467
+ }) ,
465
468
},
466
469
{
467
470
testName : "'edit' with amend file" ,
@@ -486,11 +489,11 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
486
489
},
487
490
amendFileExists : false ,
488
491
messageFileExists : true ,
489
- expectedResult : & models.Commit {
492
+ expectedResult : models .NewCommit (models. NewCommitOpts {
490
493
Hash : "fa1afe1" ,
491
494
Action : todo .Edit ,
492
495
Status : models .StatusConflicted ,
493
- },
496
+ }) ,
494
497
},
495
498
{
496
499
testName : "'edit' without amend and without message file" ,
@@ -531,36 +534,36 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
531
534
532
535
func TestCommitLoader_setCommitMergedStatuses (t * testing.T ) {
533
536
type scenario struct {
534
- testName string
535
- commits []* models.Commit
536
- ancestor string
537
- expectedCommits []* models.Commit
537
+ testName string
538
+ commitOpts []models.NewCommitOpts
539
+ ancestor string
540
+ expectedCommitOpts []models.NewCommitOpts
538
541
}
539
542
540
543
scenarios := []scenario {
541
544
{
542
545
testName : "basic" ,
543
- commits : []* models.Commit {
546
+ commitOpts : []models.NewCommitOpts {
544
547
{Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
545
548
{Hash : "67890" , Name : "2" , Action : models .ActionNone , Status : models .StatusPushed },
546
549
{Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusPushed },
547
550
},
548
551
ancestor : "67890" ,
549
- expectedCommits : []* models.Commit {
552
+ expectedCommitOpts : []models.NewCommitOpts {
550
553
{Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
551
554
{Hash : "67890" , Name : "2" , Action : models .ActionNone , Status : models .StatusMerged },
552
555
{Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusMerged },
553
556
},
554
557
},
555
558
{
556
559
testName : "with update-ref" ,
557
- commits : []* models.Commit {
560
+ commitOpts : []models.NewCommitOpts {
558
561
{Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
559
562
{Hash : "" , Name : "" , Action : todo .UpdateRef , Status : models .StatusNone },
560
563
{Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusPushed },
561
564
},
562
565
ancestor : "deadbeef" ,
563
- expectedCommits : []* models.Commit {
566
+ expectedCommitOpts : []models.NewCommitOpts {
564
567
{Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
565
568
{Hash : "" , Name : "" , Action : todo .UpdateRef , Status : models .StatusNone },
566
569
{Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusPushed },
@@ -570,9 +573,12 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
570
573
571
574
for _ , scenario := range scenarios {
572
575
t .Run (scenario .testName , func (t * testing.T ) {
573
- commits := scenario .commits
576
+ commits := lo .Map (scenario .commitOpts ,
577
+ func (opts models.NewCommitOpts , _ int ) * models.Commit { return models .NewCommit (opts ) })
574
578
setCommitMergedStatuses (scenario .ancestor , commits )
575
- assert .Equal (t , scenario .expectedCommits , commits )
579
+ expectedCommits := lo .Map (scenario .expectedCommitOpts ,
580
+ func (opts models.NewCommitOpts , _ int ) * models.Commit { return models .NewCommit (opts ) })
581
+ assert .Equal (t , expectedCommits , commits )
576
582
})
577
583
}
578
584
}
0 commit comments