diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-06-26 14:59:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-26 06:59:15 +0000 |
commit | d44a415bf019393b85a33aa31244f52d43f55080 (patch) | |
tree | 1b301660bd5bf05c6842143021cd70367a833e24 /services | |
parent | 48e5a74f215d78813a816c57fc5a85a909a003d5 (diff) | |
download | gitea-d44a415bf019393b85a33aa31244f52d43f55080.tar.gz gitea-d44a415bf019393b85a33aa31244f52d43f55080.zip |
Add Adopt repository event and handler (#25497)
Fix #14304
---------
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'services')
-rw-r--r-- | services/repository/adopt.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 55e77a78a7..e07ff35041 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -70,9 +70,17 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts repo_mo if err := repo_module.CreateRepositoryByExample(ctx, doer, u, repo, true, false); err != nil { return err } - if err := adoptRepository(ctx, repoPath, doer, repo, opts); err != nil { + + // Re-fetch the repository from database before updating it (else it would + // override changes that were done earlier with sql) + if repo, err = repo_model.GetRepositoryByID(ctx, repo.ID); err != nil { + return fmt.Errorf("getRepositoryByID: %w", err) + } + + if err := adoptRepository(ctx, repoPath, doer, repo, opts.DefaultBranch); err != nil { return fmt.Errorf("createDelegateHooks: %w", err) } + if err := repo_module.CheckDaemonExportOK(ctx, repo); err != nil { return fmt.Errorf("checkDaemonExportOK: %w", err) } @@ -95,12 +103,12 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts repo_mo return nil, err } - notification.NotifyCreateRepository(ctx, doer, u, repo) + notification.NotifyAdoptRepository(ctx, doer, u, repo) return repo, nil } -func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, opts repo_module.CreateRepoOptions) (err error) { +func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, repo *repo_model.Repository, defaultBranch string) (err error) { isExist, err := util.IsExist(repoPath) if err != nil { log.Error("Unable to check if %s exists. Error: %v", repoPath, err) @@ -114,12 +122,6 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r return fmt.Errorf("createDelegateHooks: %w", err) } - // Re-fetch the repository from database before updating it (else it would - // override changes that were done earlier with sql) - if repo, err = repo_model.GetRepositoryByID(ctx, repo.ID); err != nil { - return fmt.Errorf("getRepositoryByID: %w", err) - } - repo.IsEmpty = false // Don't bother looking this repo in the context it won't be there @@ -129,8 +131,8 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r } defer gitRepo.Close() - if len(opts.DefaultBranch) > 0 { - repo.DefaultBranch = opts.DefaultBranch + if len(defaultBranch) > 0 { + repo.DefaultBranch = defaultBranch if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { return fmt.Errorf("setDefaultBranch: %w", err) |