@@ -52,7 +52,7 @@ type CreateRepoOptions struct {
52
52
ObjectFormatName string
53
53
}
54
54
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 {
56
56
commitTimeStr := time .Now ().Format (time .RFC3339 )
57
57
authorSig := repo .Owner .NewGitSig ()
58
58
@@ -67,7 +67,7 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
67
67
)
68
68
69
69
// 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 ).
71
71
RunStdString (ctx , & git.RunOpts {Dir : "" , Env : env }); err != nil {
72
72
log .Error ("Failed to clone from %v into %s: stdout: %s\n Error: %v" , repo , tmpDir , stdout , err )
73
73
return fmt .Errorf ("git clone: %w" , err )
@@ -139,24 +139,24 @@ func prepareRepoCommit(ctx context.Context, repo *repo_model.Repository, tmpDir,
139
139
}
140
140
141
141
// 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 {
144
144
return err
145
145
}
146
146
147
147
// Initialize repository according to user's choice.
148
148
if opts .AutoInit {
149
149
tmpDir , err := os .MkdirTemp (os .TempDir (), "gitea-" + repo .Name )
150
150
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 )
152
152
}
153
153
defer func () {
154
154
if err := util .RemoveAll (tmpDir ); err != nil {
155
155
log .Warn ("Unable to remove temporary directory: %s: Error: %v" , tmpDir , err )
156
156
}
157
157
}()
158
158
159
- if err = prepareRepoCommit (ctx , repo , tmpDir , repoPath , opts ); err != nil {
159
+ if err = prepareRepoCommit (ctx , repo , tmpDir , opts ); err != nil {
160
160
return fmt .Errorf ("prepareRepoCommit: %w" , err )
161
161
}
162
162
@@ -256,10 +256,9 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
256
256
return nil
257
257
}
258
258
259
- repoPath := repo_model .RepoPath (u .Name , repo .Name )
260
- isExist , err := util .IsExist (repoPath )
259
+ isExist , err := gitrepo .IsRepositoryExist (ctx , repo )
261
260
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 )
263
262
return err
264
263
}
265
264
if isExist {
@@ -270,15 +269,15 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
270
269
//
271
270
// Previously Gitea would just delete and start afresh - this was naughty.
272
271
// 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 () )
274
273
return repo_model.ErrRepoFilesAlreadyExist {
275
274
Uname : u .Name ,
276
275
Name : repo .Name ,
277
276
}
278
277
}
279
278
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 {
282
281
log .Error ("initRepository: %v" , err )
283
282
return fmt .Errorf (
284
283
"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
300
299
}
301
300
302
301
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 {
304
303
log .Error ("CreateRepository(git update-server-info) in %v: Stdout: %s\n Error: %v" , repo , stdout , err )
305
304
rollbackRepo = repo
306
305
rollbackRepo .OwnerID = u .ID
@@ -312,7 +311,7 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt
312
311
if len (opts .License ) > 0 {
313
312
licenses = append (licenses , opts .License )
314
313
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 () })
316
315
if err != nil {
317
316
log .Error ("CreateRepository(git rev-parse HEAD) in %v: Stdout: %s\n Error: %v" , repo , stdout , err )
318
317
rollbackRepo = repo
@@ -353,14 +352,13 @@ func CreateRepositoryByExample(ctx context.Context, doer, u *user_model.User, re
353
352
}
354
353
}
355
354
356
- repoPath := repo_model .RepoPath (u .Name , repo .Name )
357
- isExist , err := util .IsExist (repoPath )
355
+ isExist , err := gitrepo .IsRepositoryExist (ctx , repo )
358
356
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 )
360
358
return err
361
359
}
362
360
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 () )
364
362
return repo_model.ErrRepoFilesAlreadyExist {
365
363
Uname : u .Name ,
366
364
Name : repo .Name ,
0 commit comments