@@ -12,16 +12,16 @@ import (
12
12
13
13
"code.gitea.io/gitea/models"
14
14
"code.gitea.io/gitea/modules/git"
15
- "code.gitea.io/gitea/modules/repofiles"
16
15
"code.gitea.io/gitea/modules/setting"
17
16
api "code.gitea.io/gitea/modules/structs"
18
17
"code.gitea.io/gitea/modules/test"
18
+ files_service "code.gitea.io/gitea/services/repository/files"
19
19
20
20
"github.com/stretchr/testify/assert"
21
21
)
22
22
23
- func getCreateRepoFileOptions (repo * models.Repository ) * repofiles .UpdateRepoFileOptions {
24
- return & repofiles .UpdateRepoFileOptions {
23
+ func getCreateRepoFileOptions (repo * models.Repository ) * files_service .UpdateRepoFileOptions {
24
+ return & files_service .UpdateRepoFileOptions {
25
25
OldBranch : repo .DefaultBranch ,
26
26
NewBranch : repo .DefaultBranch ,
27
27
TreePath : "new/file.txt" ,
@@ -33,8 +33,8 @@ func getCreateRepoFileOptions(repo *models.Repository) *repofiles.UpdateRepoFile
33
33
}
34
34
}
35
35
36
- func getUpdateRepoFileOptions (repo * models.Repository ) * repofiles .UpdateRepoFileOptions {
37
- return & repofiles .UpdateRepoFileOptions {
36
+ func getUpdateRepoFileOptions (repo * models.Repository ) * files_service .UpdateRepoFileOptions {
37
+ return & files_service .UpdateRepoFileOptions {
38
38
OldBranch : repo .DefaultBranch ,
39
39
NewBranch : repo .DefaultBranch ,
40
40
TreePath : "README.md" ,
@@ -198,7 +198,7 @@ func TestCreateOrUpdateRepoFileForCreate(t *testing.T) {
198
198
opts := getCreateRepoFileOptions (repo )
199
199
200
200
// test
201
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
201
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
202
202
203
203
// asserts
204
204
assert .NoError (t , err )
@@ -234,7 +234,7 @@ func TestCreateOrUpdateRepoFileForUpdate(t *testing.T) {
234
234
opts := getUpdateRepoFileOptions (repo )
235
235
236
236
// test
237
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
237
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
238
238
239
239
// asserts
240
240
assert .NoError (t , err )
@@ -269,7 +269,7 @@ func TestCreateOrUpdateRepoFileForUpdateWithFileMove(t *testing.T) {
269
269
opts .TreePath = "README_new.md" // new file name, README_new.md
270
270
271
271
// test
272
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
272
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
273
273
274
274
// asserts
275
275
assert .NoError (t , err )
@@ -319,7 +319,7 @@ func TestCreateOrUpdateRepoFileWithoutBranchNames(t *testing.T) {
319
319
opts .NewBranch = ""
320
320
321
321
// test
322
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
322
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
323
323
324
324
// asserts
325
325
assert .NoError (t , err )
@@ -349,7 +349,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
349
349
t .Run ("bad branch" , func (t * testing.T ) {
350
350
opts := getUpdateRepoFileOptions (repo )
351
351
opts .OldBranch = "bad_branch"
352
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
352
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
353
353
assert .Error (t , err )
354
354
assert .Nil (t , fileResponse )
355
355
expectedError := "branch does not exist [name: " + opts .OldBranch + "]"
@@ -360,7 +360,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
360
360
opts := getUpdateRepoFileOptions (repo )
361
361
origSHA := opts .SHA
362
362
opts .SHA = "bad_sha"
363
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
363
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
364
364
assert .Nil (t , fileResponse )
365
365
assert .Error (t , err )
366
366
expectedError := "sha does not match [given: " + opts .SHA + ", expected: " + origSHA + "]"
@@ -370,7 +370,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
370
370
t .Run ("new branch already exists" , func (t * testing.T ) {
371
371
opts := getUpdateRepoFileOptions (repo )
372
372
opts .NewBranch = "develop"
373
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
373
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
374
374
assert .Nil (t , fileResponse )
375
375
assert .Error (t , err )
376
376
expectedError := "branch already exists [name: " + opts .NewBranch + "]"
@@ -380,7 +380,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
380
380
t .Run ("treePath is empty:" , func (t * testing.T ) {
381
381
opts := getUpdateRepoFileOptions (repo )
382
382
opts .TreePath = ""
383
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
383
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
384
384
assert .Nil (t , fileResponse )
385
385
assert .Error (t , err )
386
386
expectedError := "path contains a malformed path component [path: ]"
@@ -390,7 +390,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
390
390
t .Run ("treePath is a git directory:" , func (t * testing.T ) {
391
391
opts := getUpdateRepoFileOptions (repo )
392
392
opts .TreePath = ".git"
393
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
393
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
394
394
assert .Nil (t , fileResponse )
395
395
assert .Error (t , err )
396
396
expectedError := "path contains a malformed path component [path: " + opts .TreePath + "]"
@@ -400,7 +400,7 @@ func TestCreateOrUpdateRepoFileErrors(t *testing.T) {
400
400
t .Run ("create file that already exists" , func (t * testing.T ) {
401
401
opts := getCreateRepoFileOptions (repo )
402
402
opts .TreePath = "README.md" //already exists
403
- fileResponse , err := repofiles .CreateOrUpdateRepoFile (repo , doer , opts )
403
+ fileResponse , err := files_service .CreateOrUpdateRepoFile (repo , doer , opts )
404
404
assert .Nil (t , fileResponse )
405
405
assert .Error (t , err )
406
406
expectedError := "repository file already exists [path: " + opts .TreePath + "]"
0 commit comments