@@ -249,7 +249,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
249249
250250 // 1 - create the repository database operations first
251251 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 )
253253 })
254254 if err != nil {
255255 return nil , err
@@ -284,10 +284,12 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
284284 // Previously Gitea would just delete and start afresh - this was naughty.
285285 // So we will now fail and delegate to other functionality to adopt or delete
286286 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 ,
289290 Name : repo .Name ,
290291 }
292+ return nil , err
291293 }
292294
293295 if err = initRepository (ctx , doer , repo , opts ); err != nil {
@@ -331,8 +333,8 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
331333 return repo , nil
332334}
333335
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 ) {
336338 if err = repo_model .IsUsableRepoName (repo .Name ); err != nil {
337339 return err
338340 }
@@ -347,29 +349,6 @@ func CreateRepositoryInDB(ctx context.Context, doer, u *user_model.User, repo *r
347349 }
348350 }
349351
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-
373352 if err = db .Insert (ctx , repo ); err != nil {
374353 return err
375354 }
0 commit comments