@@ -249,7 +249,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
249
249
250
250
// 1 - create the repository database operations first
251
251
err := db .WithTx (ctx , func (ctx context.Context ) error {
252
- return CreateRepositoryInDB (ctx , doer , u , repo , false , false )
252
+ return createRepositoryInDB (ctx , doer , u , repo , false )
253
253
})
254
254
if err != nil {
255
255
return nil , err
@@ -284,10 +284,12 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
284
284
// Previously Gitea would just delete and start afresh - this was naughty.
285
285
// So we will now fail and delegate to other functionality to adopt or delete
286
286
log .Error ("Files already exist in %s and we are not going to adopt or delete." , repo .FullName ())
287
- return nil , repo_model.ErrRepoFilesAlreadyExist {
288
- Uname : u .Name ,
287
+ // we need err in defer to cleanupRepository
288
+ err = repo_model.ErrRepoFilesAlreadyExist {
289
+ Uname : repo .OwnerName ,
289
290
Name : repo .Name ,
290
291
}
292
+ return nil , err
291
293
}
292
294
293
295
if err = initRepository (ctx , doer , repo , opts ); err != nil {
@@ -331,8 +333,8 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
331
333
return repo , nil
332
334
}
333
335
334
- // CreateRepositoryInDB creates a repository for the user/organization.
335
- func CreateRepositoryInDB (ctx context.Context , doer , u * user_model.User , repo * repo_model.Repository , overwriteOrAdopt , isFork bool ) (err error ) {
336
+ // createRepositoryInDB creates a repository for the user/organization.
337
+ func createRepositoryInDB (ctx context.Context , doer , u * user_model.User , repo * repo_model.Repository , isFork bool ) (err error ) {
336
338
if err = repo_model .IsUsableRepoName (repo .Name ); err != nil {
337
339
return err
338
340
}
@@ -347,29 +349,6 @@ func CreateRepositoryInDB(ctx context.Context, doer, u *user_model.User, repo *r
347
349
}
348
350
}
349
351
350
- isExist , err := gitrepo .IsRepositoryExist (ctx , repo )
351
- if err != nil {
352
- log .Error ("Unable to check if %s exists. Error: %v" , repo .FullName (), err )
353
- return err
354
- }
355
- if overwriteOrAdopt != isExist {
356
- if overwriteOrAdopt {
357
- // repo should exist but doesn't - We have two or three options.
358
- log .Error ("Files do not exist in %s and we are not going to adopt or delete." , repo .FullName ())
359
- return repo_model.ErrRepoNotExist {
360
- OwnerName : u .Name ,
361
- Name : repo .Name ,
362
- }
363
- }
364
-
365
- // repo already exists - We have two or three options.
366
- log .Error ("Files already exist in %s and we are not going to adopt or delete." , repo .FullName ())
367
- return repo_model.ErrRepoFilesAlreadyExist {
368
- Uname : u .Name ,
369
- Name : repo .Name ,
370
- }
371
- }
372
-
373
352
if err = db .Insert (ctx , repo ); err != nil {
374
353
return err
375
354
}
0 commit comments