6
6
"testing"
7
7
8
8
"github.com/go-errors/errors"
9
+ "github.com/jesseduffield/generics/set"
9
10
"github.com/jesseduffield/lazygit/pkg/commands/models"
10
11
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
11
12
"github.com/jesseduffield/lazygit/pkg/common"
@@ -43,7 +44,7 @@ func TestGetCommits(t *testing.T) {
43
44
logOrder : "topo-order" ,
44
45
opts : GetCommitsOptions {RefName : "HEAD" , RefForPushedStatus : & models.Branch {Name : "mybranch" }, IncludeRebaseCommits : false },
45
46
runner : oscommands .NewFakeRunner (t ).
46
- ExpectGitArgs ([]string {"merge-base " , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164 " , nil ).
47
+ ExpectGitArgs ([]string {"rev-list " , "refs/heads/mybranch" , "^ mybranch@{u}" }, "" , nil ).
47
48
ExpectGitArgs ([]string {"log" , "HEAD" , "--topo-order" , "--oneline" , "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, "" , nil ),
48
49
49
50
expectedCommitOpts : []models.NewCommitOpts {},
@@ -54,7 +55,7 @@ func TestGetCommits(t *testing.T) {
54
55
logOrder : "topo-order" ,
55
56
opts : GetCommitsOptions {RefName : "refs/heads/mybranch" , RefForPushedStatus : & models.Branch {Name : "mybranch" }, IncludeRebaseCommits : false },
56
57
runner : oscommands .NewFakeRunner (t ).
57
- ExpectGitArgs ([]string {"merge-base " , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164 " , nil ).
58
+ ExpectGitArgs ([]string {"rev-list " , "refs/heads/mybranch" , "^ mybranch@{u}" }, "" , nil ).
58
59
ExpectGitArgs ([]string {"log" , "refs/heads/mybranch" , "--topo-order" , "--oneline" , "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, "" , nil ),
59
60
60
61
expectedCommitOpts : []models.NewCommitOpts {},
@@ -67,7 +68,7 @@ func TestGetCommits(t *testing.T) {
67
68
mainBranches : []string {"master" , "main" , "develop" },
68
69
runner : oscommands .NewFakeRunner (t ).
69
70
// here it's seeing which commits are yet to be pushed
70
- ExpectGitArgs ([]string {"merge-base " , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164 " , nil ).
71
+ ExpectGitArgs ([]string {"rev-list " , "refs/heads/mybranch" , "^ mybranch@{u}" , "^refs/remotes/origin/master" , "^refs/remotes/origin/main" }, "0eea75e8c631fba6b58135697835d58ba4c18dbc \n " , nil ).
71
72
// here it's actually getting all the commits in a formatted form, one per line
72
73
ExpectGitArgs ([]string {"log" , "HEAD" , "--topo-order" , "--oneline" , "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, commitsOutput , nil ).
73
74
// here it's testing which of the configured main branches have an upstream
@@ -77,8 +78,9 @@ func TestGetCommits(t *testing.T) {
77
78
ExpectGitArgs ([]string {"rev-parse" , "--symbolic-full-name" , "develop@{u}" }, "" , errors .New ("error" )). // this one doesn't, so it checks origin instead
78
79
ExpectGitArgs ([]string {"rev-parse" , "--verify" , "--quiet" , "refs/remotes/origin/develop" }, "" , errors .New ("error" )). // doesn't exist there, either, so it checks for a local branch
79
80
ExpectGitArgs ([]string {"rev-parse" , "--verify" , "--quiet" , "refs/heads/develop" }, "" , errors .New ("error" )). // no local branch either
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'
81
- ExpectGitArgs ([]string {"merge-base" , "HEAD" , "refs/remotes/origin/master" , "refs/remotes/origin/main" }, "26c07b1ab33860a1a7591a0638f9925ccf497ffa" , nil ),
81
+ // here it's seeing which of our commits are not on any of the main branches yet
82
+ ExpectGitArgs ([]string {"rev-list" , "HEAD" , "^refs/remotes/origin/master" , "^refs/remotes/origin/main" },
83
+ "0eea75e8c631fba6b58135697835d58ba4c18dbc\n b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164\n e94e8fc5b6fab4cb755f29f1bdb3ee5e001df35c\n d8084cd558925eb7c9c38afeed5725c21653ab90\n 65f910ebd85283b5cce9bf67d03d3f1a9ea3813a\n " , nil ),
82
84
83
85
expectedCommitOpts : []models.NewCommitOpts {
84
86
{
@@ -197,13 +199,13 @@ func TestGetCommits(t *testing.T) {
197
199
expectedError : nil ,
198
200
},
199
201
{
200
- testName : "should not call merge-base for mainBranches if none exist" ,
202
+ testName : "should not call rev-list for mainBranches if none exist" ,
201
203
logOrder : "topo-order" ,
202
204
opts : GetCommitsOptions {RefName : "HEAD" , RefForPushedStatus : & models.Branch {Name : "mybranch" }, IncludeRebaseCommits : false },
203
205
mainBranches : []string {"master" , "main" },
204
206
runner : oscommands .NewFakeRunner (t ).
205
207
// here it's seeing which commits are yet to be pushed
206
- ExpectGitArgs ([]string {"merge-base " , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164 " , nil ).
208
+ ExpectGitArgs ([]string {"rev-list " , "refs/heads/mybranch" , "^ mybranch@{u}" }, "0eea75e8c631fba6b58135697835d58ba4c18dbc \n " , nil ).
207
209
// here it's actually getting all the commits in a formatted form, one per line
208
210
ExpectGitArgs ([]string {"log" , "HEAD" , "--topo-order" , "--oneline" , "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, singleCommitOutput , nil ).
209
211
// here it's testing which of the configured main branches exist; neither does
@@ -233,13 +235,13 @@ func TestGetCommits(t *testing.T) {
233
235
expectedError : nil ,
234
236
},
235
237
{
236
- testName : "should call merge-base for all main branches that exist" ,
238
+ testName : "should call rev-list with all main branches that exist" ,
237
239
logOrder : "topo-order" ,
238
240
opts : GetCommitsOptions {RefName : "HEAD" , RefForPushedStatus : & models.Branch {Name : "mybranch" }, IncludeRebaseCommits : false },
239
241
mainBranches : []string {"master" , "main" , "develop" , "1.0-hotfixes" },
240
242
runner : oscommands .NewFakeRunner (t ).
241
243
// here it's seeing which commits are yet to be pushed
242
- ExpectGitArgs ([]string {"merge-base " , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164 " , nil ).
244
+ ExpectGitArgs ([]string {"rev-list " , "refs/heads/mybranch" , "^ mybranch@{u}" , "^refs/remotes/origin/master" , "^refs/remotes/origin/develop" , "^refs/remotes/origin/1.0-hotfixes" }, "0eea75e8c631fba6b58135697835d58ba4c18dbc \n " , nil ).
243
245
// here it's actually getting all the commits in a formatted form, one per line
244
246
ExpectGitArgs ([]string {"log" , "HEAD" , "--topo-order" , "--oneline" , "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, singleCommitOutput , nil ).
245
247
// here it's testing which of the configured main branches exist
@@ -249,8 +251,8 @@ func TestGetCommits(t *testing.T) {
249
251
ExpectGitArgs ([]string {"rev-parse" , "--verify" , "--quiet" , "refs/heads/main" }, "" , errors .New ("error" )).
250
252
ExpectGitArgs ([]string {"rev-parse" , "--symbolic-full-name" , "develop@{u}" }, "refs/remotes/origin/develop" , nil ).
251
253
ExpectGitArgs ([]string {"rev-parse" , "--symbolic-full-name" , "1.0-hotfixes@{u}" }, "refs/remotes/origin/1.0-hotfixes" , nil ).
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'
253
- ExpectGitArgs ([]string {"merge-base " , "HEAD" , "refs/remotes/origin/master" , "refs/remotes/origin/develop" , "refs/remotes/origin/1.0-hotfixes" }, "26c07b1ab33860a1a7591a0638f9925ccf497ffa " , nil ),
254
+ // here it's seeing which of our commits are not on any of the main branches yet
255
+ ExpectGitArgs ([]string {"rev-list " , "HEAD" , "^ refs/remotes/origin/master" , "^ refs/remotes/origin/develop" , "^ refs/remotes/origin/1.0-hotfixes" }, "0eea75e8c631fba6b58135697835d58ba4c18dbc \n " , nil ),
254
256
255
257
expectedCommitOpts : []models.NewCommitOpts {
256
258
{
@@ -275,7 +277,7 @@ func TestGetCommits(t *testing.T) {
275
277
logOrder : "default" ,
276
278
opts : GetCommitsOptions {RefName : "HEAD" , RefForPushedStatus : & models.Branch {Name : "mybranch" }, IncludeRebaseCommits : false },
277
279
runner : oscommands .NewFakeRunner (t ).
278
- ExpectGitArgs ([]string {"merge-base " , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164 " , nil ).
280
+ ExpectGitArgs ([]string {"rev-list " , "refs/heads/mybranch" , "^ mybranch@{u}" }, "" , nil ).
279
281
ExpectGitArgs ([]string {"log" , "HEAD" , "--oneline" , "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s" , "--abbrev=40" , "--no-show-signature" , "--" }, "" , nil ),
280
282
281
283
expectedCommitOpts : []models.NewCommitOpts {},
@@ -286,7 +288,7 @@ func TestGetCommits(t *testing.T) {
286
288
logOrder : "default" ,
287
289
opts : GetCommitsOptions {RefName : "HEAD" , RefForPushedStatus : & models.Branch {Name : "mybranch" }, FilterPath : "src" },
288
290
runner : oscommands .NewFakeRunner (t ).
289
- ExpectGitArgs ([]string {"merge-base " , "refs/heads/mybranch" , "mybranch@{u}" }, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164 " , nil ).
291
+ ExpectGitArgs ([]string {"rev-list " , "refs/heads/mybranch" , "^ mybranch@{u}" }, "" , nil ).
290
292
ExpectGitArgs ([]string {"log" , "HEAD" , "--oneline" , "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s" , "--abbrev=40" , "--follow" , "--name-status" , "--no-show-signature" , "--" , "src" }, "" , nil ),
291
293
292
294
expectedCommitOpts : []models.NewCommitOpts {},
@@ -536,37 +538,39 @@ func TestCommitLoader_getConflictedCommitImpl(t *testing.T) {
536
538
}
537
539
}
538
540
539
- func TestCommitLoader_setCommitMergedStatuses (t * testing.T ) {
541
+ func TestCommitLoader_setCommitStatuses (t * testing.T ) {
540
542
type scenario struct {
541
543
testName string
542
544
commitOpts []models.NewCommitOpts
543
- ancestor string
545
+ unmergedCommits []string
546
+ unpushedCommits []string
544
547
expectedCommitOpts []models.NewCommitOpts
545
548
}
546
549
547
550
scenarios := []scenario {
548
551
{
549
552
testName : "basic" ,
550
553
commitOpts : []models.NewCommitOpts {
551
- {Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models . StatusUnpushed },
552
- {Hash : "67890" , Name : "2" , Action : models .ActionNone , Status : models . StatusPushed },
553
- {Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models . StatusPushed },
554
+ {Hash : "12345" , Name : "1" , Action : models .ActionNone },
555
+ {Hash : "67890" , Name : "2" , Action : models .ActionNone },
556
+ {Hash : "abcde" , Name : "3" , Action : models .ActionNone },
554
557
},
555
- ancestor : "67890" ,
558
+ unmergedCommits : [] string { "12345" } ,
556
559
expectedCommitOpts : []models.NewCommitOpts {
557
- {Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
560
+ {Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusPushed },
558
561
{Hash : "67890" , Name : "2" , Action : models .ActionNone , Status : models .StatusMerged },
559
562
{Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models .StatusMerged },
560
563
},
561
564
},
562
565
{
563
566
testName : "with update-ref" ,
564
567
commitOpts : []models.NewCommitOpts {
565
- {Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models . StatusUnpushed },
566
- {Hash : "" , Name : "" , Action : todo .UpdateRef , Status : models . StatusNone },
567
- {Hash : "abcde" , Name : "3" , Action : models .ActionNone , Status : models . StatusPushed },
568
+ {Hash : "12345" , Name : "1" , Action : models .ActionNone },
569
+ {Hash : "" , Name : "" , Action : todo .UpdateRef },
570
+ {Hash : "abcde" , Name : "3" , Action : models .ActionNone },
568
571
},
569
- ancestor : "deadbeef" ,
572
+ unmergedCommits : []string {"12345" , "abcde" },
573
+ unpushedCommits : []string {"12345" },
570
574
expectedCommitOpts : []models.NewCommitOpts {
571
575
{Hash : "12345" , Name : "1" , Action : models .ActionNone , Status : models .StatusUnpushed },
572
576
{Hash : "" , Name : "" , Action : todo .UpdateRef , Status : models .StatusNone },
@@ -581,7 +585,7 @@ func TestCommitLoader_setCommitMergedStatuses(t *testing.T) {
581
585
582
586
commits := lo .Map (scenario .commitOpts ,
583
587
func (opts models.NewCommitOpts , _ int ) * models.Commit { return models .NewCommit (hashPool , opts ) })
584
- setCommitMergedStatuses ( scenario .ancestor , commits )
588
+ setCommitStatuses ( set . NewFromSlice ( scenario .unpushedCommits ), set . NewFromSlice ( scenario . unmergedCommits ) , commits )
585
589
expectedCommits := lo .Map (scenario .expectedCommitOpts ,
586
590
func (opts models.NewCommitOpts , _ int ) * models.Commit { return models .NewCommit (hashPool , opts ) })
587
591
assert .Equal (t , expectedCommits , commits )
0 commit comments