@@ -52,7 +52,7 @@ type CreateRepoOptions struct {
5252 ObjectFormatName string
5353}
5454
55- func prepareRepoCommit (ctx context.Context , repo * repo_model.Repository , tmpDir , repoPath string , opts CreateRepoOptions ) error {
55+ func prepareRepoCommit (ctx context.Context , repo * repo_model.Repository , tmpDir string , opts CreateRepoOptions ) error {
5656 commitTimeStr := time .Now ().Format (time .RFC3339 )
5757 authorSig := repo .Owner .NewGitSig ()
5858
@@ -67,7 +67,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
6767 )
6868
6969 // Clone to temporary path and do the init commit.
70- if stdout , _ , err := git .NewCommand ("clone" ).AddDynamicArguments (repoPath , tmpDir ).
70+ if stdout , _ , err := git .NewCommand ("clone" ).AddDynamicArguments (repo . RepoPath () , tmpDir ).
7171 RunStdString (ctx , & git.RunOpts {Dir : "" , Env : env }); err != nil {
7272 log .Error ("Failed to clone from %v into %s: stdout: %s\n Error: %v" , repo , tmpDir , stdout , err )
7373 return fmt .Errorf ("git clone: %w" , err )
@@ -139,24 +139,24 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
139139}
140140
141141// InitRepository initializes README and .gitignore if needed.
142- func initRepository (ctx context.Context , repoPath string , u * user_model.User , repo * repo_model.Repository , opts CreateRepoOptions ) (err error ) {
143- if err = repo_module .CheckInitRepository (ctx , repo . OwnerName , repo . Name , opts . ObjectFormatName ); err != nil {
142+ func initRepository (ctx context.Context , u * user_model.User , repo * repo_model.Repository , opts CreateRepoOptions ) (err error ) {
143+ if err = repo_module .CheckInitRepository (ctx , repo ); err != nil {
144144 return err
145145 }
146146
147147 // Initialize repository according to user's choice.
148148 if opts .AutoInit {
149149 tmpDir , err := os .MkdirTemp (os .TempDir (), "gitea-" + repo .Name )
150150 if err != nil {
151- return fmt .Errorf ("Failed to create temp dir for repository %s: %w" , repo .RepoPath (), err )
151+ return fmt .Errorf ("Failed to create temp dir for repository %s: %w" , repo .FullName (), err )
152152 }
153153 defer func () {
154154 if err := util .RemoveAll (tmpDir ); err != nil {
155155 log .Warn ("Unable to remove temporary directory: %s: Error: %v" , tmpDir , err )
156156 }
157157 }()
158158
159- if err = prepareRepoCommit (ctx , repo , tmpDir , repoPath , opts ); err != nil {
159+ if err = prepareRepoCommit (ctx , repo , tmpDir , opts ); err != nil {
160160 return fmt .Errorf ("prepareRepoCommit: %w" , err )
161161 }
162162
@@ -256,10 +256,9 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
256256 return nil
257257 }
258258
259- repoPath := repo_model .RepoPath (u .Name , repo .Name )
260- isExist , err := util .IsExist (repoPath )
259+ isExist , err := gitrepo .IsRepositoryExist (ctx , repo )
261260 if err != nil {
262- log .Error ("Unable to check if %s exists. Error: %v" , repoPath , err )
261+ log .Error ("Unable to check if %s exists. Error: %v" , repo . FullName () , err )
263262 return err
264263 }
265264 if isExist {
@@ -270,15 +269,15 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
270269 //
271270 // Previously Gitea would just delete and start afresh - this was naughty.
272271 // So we will now fail and delegate to other functionality to adopt or delete
273- log .Error ("Files already exist in %s and we are not going to adopt or delete." , repoPath )
272+ log .Error ("Files already exist in %s and we are not going to adopt or delete." , repo . FullName () )
274273 return repo_model.ErrRepoFilesAlreadyExist {
275274 Uname : u .Name ,
276275 Name : repo .Name ,
277276 }
278277 }
279278
280- if err = initRepository (ctx , repoPath , doer , repo , opts ); err != nil {
281- if err2 := util .RemoveAll (repoPath ); err2 != nil {
279+ if err = initRepository (ctx , doer , repo , opts ); err != nil {
280+ if err2 := util .RemoveAll (repo . RepoPath () ); err2 != nil {
282281 log .Error ("initRepository: %v" , err )
283282 return fmt .Errorf (
284283 "delete repo directory %s/%s failed(2): %v" , u .Name , repo .Name , err2 )
@@ -300,7 +299,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
300299 }
301300
302301 if stdout , _ , err := git .NewCommand ("update-server-info" ).
303- RunStdString (ctx , & git.RunOpts {Dir : repoPath }); err != nil {
302+ RunStdString (ctx , & git.RunOpts {Dir : repo . RepoPath () }); err != nil {
304303 log .Error ("CreateRepository(git update-server-info) in %v: Stdout: %s\n Error: %v" , repo , stdout , err )
305304 rollbackRepo = repo
306305 rollbackRepo .OwnerID = u .ID
@@ -312,7 +311,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
312311 if len (opts .License ) > 0 {
313312 licenses = append (licenses , opts .License )
314313
315- stdout , _ , err := git .NewCommand ("rev-parse" , "HEAD" ).RunStdString (ctx , & git.RunOpts {Dir : repoPath })
314+ stdout , _ , err := git .NewCommand ("rev-parse" , "HEAD" ).RunStdString (ctx , & git.RunOpts {Dir : repo . RepoPath () })
316315 if err != nil {
317316 log .Error ("CreateRepository(git rev-parse HEAD) in %v: Stdout: %s\n Error: %v" , repo , stdout , err )
318317 rollbackRepo = repo
@@ -353,14 +352,13 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
353352 }
354353 }
355354
356- repoPath := repo_model .RepoPath (u .Name , repo .Name )
357- isExist , err := util .IsExist (repoPath )
355+ isExist , err := gitrepo .IsRepositoryExist (ctx , repo )
358356 if err != nil {
359- log .Error ("Unable to check if %s exists. Error: %v" , repoPath , err )
357+ log .Error ("Unable to check if %s exists. Error: %v" , repo . FullName () , err )
360358 return err
361359 }
362360 if ! overwriteOrAdopt && isExist {
363- log .Error ("Files already exist in %s and we are not going to adopt or delete." , repoPath )
361+ log .Error ("Files already exist in %s and we are not going to adopt or delete." , repo . FullName () )
364362 return repo_model.ErrRepoFilesAlreadyExist {
365363 Uname : u .Name ,
366364 Name : repo .Name ,
0 commit comments