@@ -8,7 +8,11 @@ import (
88 "path/filepath"
99 "testing"
1010
11+ "code.gitea.io/gitea/modules/setting"
12+ "code.gitea.io/gitea/modules/test"
13+
1114 "github.com/stretchr/testify/assert"
15+ "github.com/stretchr/testify/require"
1216)
1317
1418func TestRepository_GetCommitBranches (t * testing.T ) {
@@ -126,3 +130,21 @@ func TestGetRefCommitID(t *testing.T) {
126130 }
127131 }
128132}
133+
134+ func TestCommitsByFileAndRange (t * testing.T ) {
135+ defer test .MockVariableValue (& setting .Git .CommitsRangeSize , 2 )()
136+
137+ bareRepo1Path := filepath .Join (testReposDir , "repo1_bare" )
138+ bareRepo1 , err := openRepositoryWithDefaultContext (bareRepo1Path )
139+ require .NoError (t , err )
140+ defer bareRepo1 .Close ()
141+
142+ // "foo" has 3 commits in "master" branch
143+ commits , err := bareRepo1 .CommitsByFileAndRange (CommitsByFileAndRangeOptions {Revision : "master" , File : "foo" , Page : 1 })
144+ require .NoError (t , err )
145+ assert .Len (t , commits , 2 )
146+
147+ commits , err = bareRepo1 .CommitsByFileAndRange (CommitsByFileAndRangeOptions {Revision : "master" , File : "foo" , Page : 2 })
148+ require .NoError (t , err )
149+ assert .Len (t , commits , 1 )
150+ }
0 commit comments