@@ -10,6 +10,7 @@ import (
1010 "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
1111 "github.com/jesseduffield/lazygit/pkg/config"
1212 "github.com/jesseduffield/lazygit/pkg/utils"
13+ "github.com/samber/lo"
1314 "github.com/stefanhaller/git-todo-parser/todo"
1415 "github.com/stretchr/testify/assert"
1516)
@@ -27,13 +28,13 @@ var singleCommitOutput = strings.Replace(`0eea75e8c631fba6b58135697835d58ba4c18d
2728
2829func TestGetCommits (t * testing.T ) {
2930 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
3738 }
3839
3940 scenarios := []scenario {
@@ -45,8 +46,8 @@ func TestGetCommits(t *testing.T) {
4546 ExpectGitArgs ([]string {"merge-base" , "mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164" , nil ).
4647 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 ),
4748
48- expectedCommits : []* models.Commit {},
49- expectedError : nil ,
49+ expectedCommitOpts : []models.NewCommitOpts {},
50+ expectedError : nil ,
5051 },
5152 {
5253 testName : "should use proper upstream name for branch" ,
@@ -56,8 +57,8 @@ func TestGetCommits(t *testing.T) {
5657 ExpectGitArgs ([]string {"merge-base" , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164" , nil ).
5758 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 ),
5859
59- expectedCommits : []* models.Commit {},
60- expectedError : nil ,
60+ expectedCommitOpts : []models.NewCommitOpts {},
61+ expectedError : nil ,
6162 },
6263 {
6364 testName : "should return commits if they are present" ,
@@ -79,7 +80,7 @@ func TestGetCommits(t *testing.T) {
7980 // here it's seeing where our branch diverged from the master branch so that we can mark that commit and parent commits as 'merged'
8081 ExpectGitArgs ([]string {"merge-base" , "HEAD" , "refs/remotes/origin/master" , "refs/remotes/origin/main" }, "26c07b1ab33860a1a7591a0638f9925ccf497ffa" , nil ),
8182
82- expectedCommits : []* models.Commit {
83+ expectedCommitOpts : []models.NewCommitOpts {
8384 {
8485 Hash : "0eea75e8c631fba6b58135697835d58ba4c18dbc" ,
8586 Name : "better typing for rebase mode" ,
@@ -213,7 +214,7 @@ func TestGetCommits(t *testing.T) {
213214 ExpectGitArgs ([]string {"rev-parse" , "--verify" , "--quiet" , "refs/remotes/origin/main" }, "" , errors .New ("error" )).
214215 ExpectGitArgs ([]string {"rev-parse" , "--verify" , "--quiet" , "refs/heads/main" }, "" , errors .New ("error" )),
215216
216- expectedCommits : []* models.Commit {
217+ expectedCommitOpts : []models.NewCommitOpts {
217218 {
218219 Hash : "0eea75e8c631fba6b58135697835d58ba4c18dbc" ,
219220 Name : "better typing for rebase mode" ,
@@ -251,7 +252,7 @@ func TestGetCommits(t *testing.T) {
251252 // here it's seeing where our branch diverged from the master branch so that we can mark that commit and parent commits as 'merged'
252253 ExpectGitArgs ([]string {"merge-base" , "HEAD" , "refs/remotes/origin/master" , "refs/remotes/origin/develop" , "refs/remotes/origin/1.0-hotfixes" }, "26c07b1ab33860a1a7591a0638f9925ccf497ffa" , nil ),
253254
254- expectedCommits : []* models.Commit {
255+ expectedCommitOpts : []models.NewCommitOpts {
255256 {
256257 Hash : "0eea75e8c631fba6b58135697835d58ba4c18dbc" ,
257258 Name : "better typing for rebase mode" ,
@@ -277,8 +278,8 @@ func TestGetCommits(t *testing.T) {
277278 ExpectGitArgs ([]string {"merge-base" , "mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164" , nil ).
278279 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 ),
279280
280- expectedCommits : []* models.Commit {},
281- expectedError : nil ,
281+ expectedCommitOpts : []models.NewCommitOpts {},
282+ expectedError : nil ,
282283 },
283284 {
284285 testName : "should set filter path" ,
@@ -288,8 +289,8 @@ func TestGetCommits(t *testing.T) {
288289 ExpectGitArgs ([]string {"merge-base" , "mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164" , nil ).
289290 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 ),
290291
291- expectedCommits : []* models.Commit {},
292- expectedError : nil ,
292+ expectedCommitOpts : []models.NewCommitOpts {},
293+ expectedError : nil ,
293294 },
294295 }
295296
@@ -318,7 +319,9 @@ func TestGetCommits(t *testing.T) {
318319 opts .MainBranches = NewMainBranches (common , cmd )
319320 commits , err := builder .GetCommits (opts )
320321
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 )
322325 assert .Equal (t , scenario .expectedError , err )
323326
324327 scenario .runner .CheckForMissingCalls ()
@@ -356,11 +359,11 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
356359 },
357360 },
358361 amendFileExists : false ,
359- expectedResult : & models.Commit {
362+ expectedResult : models .NewCommit (models. NewCommitOpts {
360363 Hash : "fa1afe1" ,
361364 Action : todo .Pick ,
362365 Status : models .StatusConflicted ,
363- },
366+ }) ,
364367 },
365368 {
366369 testName : "last command was 'break'" ,
@@ -457,11 +460,11 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
457460 },
458461 },
459462 amendFileExists : false ,
460- expectedResult : & models.Commit {
463+ expectedResult : models .NewCommit (models. NewCommitOpts {
461464 Hash : "fa1afe1" ,
462465 Action : todo .Pick ,
463466 Status : models .StatusConflicted ,
464- },
467+ }) ,
465468 },
466469 {
467470 testName : "'edit' with amend file" ,
@@ -486,11 +489,11 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
486489 },
487490 amendFileExists : false ,
488491 messageFileExists : true ,
489- expectedResult : & models.Commit {
492+ expectedResult : models .NewCommit (models. NewCommitOpts {
490493 Hash : "fa1afe1" ,
491494 Action : todo .Edit ,
492495 Status : models .StatusConflicted ,
493- },
496+ }) ,
494497 },
495498 {
496499 testName : "'edit' without amend and without message file" ,
@@ -531,36 +534,36 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
531534
532535func TestCommitLoader_setCommitMergedStatuses (t * testing.T ) {
533536 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
538541 }
539542
540543 scenarios := []scenario {
541544 {
542545 testName : "basic" ,
543- commits : []* models.Commit {
546+ commitOpts : []models.NewCommitOpts {
544547 {Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
545548 {Hash : "67890" , Name : "2" , Action : models .ActionNone , Status : models .StatusPushed },
546549 {Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusPushed },
547550 },
548551 ancestor : "67890" ,
549- expectedCommits : []* models.Commit {
552+ expectedCommitOpts : []models.NewCommitOpts {
550553 {Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
551554 {Hash : "67890" , Name : "2" , Action : models .ActionNone , Status : models .StatusMerged },
552555 {Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusMerged },
553556 },
554557 },
555558 {
556559 testName : "with update-ref" ,
557- commits : []* models.Commit {
560+ commitOpts : []models.NewCommitOpts {
558561 {Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
559562 {Hash : "" , Name : "" , Action : todo .UpdateRef , Status : models .StatusNone },
560563 {Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusPushed },
561564 },
562565 ancestor : "deadbeef" ,
563- expectedCommits : []* models.Commit {
566+ expectedCommitOpts : []models.NewCommitOpts {
564567 {Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
565568 {Hash : "" , Name : "" , Action : todo .UpdateRef , Status : models .StatusNone },
566569 {Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusPushed },
@@ -570,9 +573,12 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
570573
571574 for _ , scenario := range scenarios {
572575 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 ) })
574578 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 )
576582 })
577583 }
578584}
0 commit comments