diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-03-08 15:30:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-08 15:30:10 +0800 |
commit | 25b842df261452a29570ba89ffc3a4842d73f68c (patch) | |
tree | 225cddc07630f491e3efb9976fb57d0d31adb38a /services/repository | |
parent | a1f5dd767729e30d07ab42fda80c19f30a72679f (diff) | |
download | gitea-25b842df261452a29570ba89ffc3a4842d73f68c.tar.gz gitea-25b842df261452a29570ba89ffc3a4842d73f68c.zip |
Move get/set default branch from git package to gitrepo package to hide repopath (#29126)
Diffstat (limited to 'services/repository')
-rw-r--r-- | services/repository/adopt.go | 22 | ||||
-rw-r--r-- | services/repository/branch.go | 4 | ||||
-rw-r--r-- | services/repository/create.go | 7 | ||||
-rw-r--r-- | services/repository/generate.go | 7 | ||||
-rw-r--r-- | services/repository/migrate.go | 9 | ||||
-rw-r--r-- | services/repository/push.go | 2 |
6 files changed, 17 insertions, 34 deletions
diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 7ca68776b5..0ac3c774b7 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -127,24 +127,17 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r repo.IsEmpty = false - // Don't bother looking this repo in the context it won't be there - gitRepo, err := gitrepo.OpenRepository(ctx, repo) - if err != nil { - return fmt.Errorf("openRepository: %w", err) - } - defer gitRepo.Close() - if len(defaultBranch) > 0 { repo.DefaultBranch = defaultBranch - if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { + if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil { return fmt.Errorf("setDefaultBranch: %w", err) } } else { - repo.DefaultBranch, err = gitRepo.GetDefaultBranch() + repo.DefaultBranch, err = gitrepo.GetDefaultBranch(ctx, repo) if err != nil { repo.DefaultBranch = setting.Repository.DefaultBranch - if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { + if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil { return fmt.Errorf("setDefaultBranch: %w", err) } } @@ -188,7 +181,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r repo.DefaultBranch = setting.Repository.DefaultBranch } - if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { + if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil { return fmt.Errorf("setDefaultBranch: %w", err) } } @@ -197,6 +190,13 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r return fmt.Errorf("updateRepository: %w", err) } + // Don't bother looking this repo in the context it won't be there + gitRepo, err := gitrepo.OpenRepository(ctx, repo) + if err != nil { + return fmt.Errorf("openRepository: %w", err) + } + defer gitRepo.Close() + if err = repo_module.SyncReleasesWithTags(ctx, repo, gitRepo); err != nil { return fmt.Errorf("SyncReleasesWithTags: %w", err) } diff --git a/services/repository/branch.go b/services/repository/branch.go index 402814fb9a..763fb966c5 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -375,7 +375,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m log.Error("CancelRunningJobs: %v", err) } - err2 = gitRepo.SetDefaultBranch(to) + err2 = gitrepo.SetDefaultBranch(ctx, repo, to) if err2 != nil { return err2 } @@ -540,7 +540,7 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, gitR log.Error("CancelRunningJobs: %v", err) } - if err := gitRepo.SetDefaultBranch(newBranchName); err != nil { + if err := gitrepo.SetDefaultBranch(ctx, repo, newBranchName); err != nil { if !git.IsErrUnsupportedVersion(err) { return err } diff --git a/services/repository/create.go b/services/repository/create.go index 8d8c39197d..971793bcc6 100644 --- a/services/repository/create.go +++ b/services/repository/create.go @@ -177,12 +177,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re if len(opts.DefaultBranch) > 0 { repo.DefaultBranch = opts.DefaultBranch - gitRepo, err := gitrepo.OpenRepository(ctx, repo) - if err != nil { - return fmt.Errorf("openRepository: %w", err) - } - defer gitRepo.Close() - if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { + if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil { return fmt.Errorf("setDefaultBranch: %w", err) } diff --git a/services/repository/generate.go b/services/repository/generate.go index c444b60b2c..9b09e271ab 100644 --- a/services/repository/generate.go +++ b/services/repository/generate.go @@ -272,12 +272,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r repo.DefaultBranch = templateRepo.DefaultBranch } - gitRepo, err := gitrepo.OpenRepository(ctx, repo) - if err != nil { - return fmt.Errorf("openRepository: %w", err) - } - defer gitRepo.Close() - if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { + if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil { return fmt.Errorf("setDefaultBranch: %w", err) } if err = UpdateRepository(ctx, repo, false); err != nil { diff --git a/services/repository/migrate.go b/services/repository/migrate.go index aae2ddc120..df5cc67ae1 100644 --- a/services/repository/migrate.go +++ b/services/repository/migrate.go @@ -57,14 +57,7 @@ func cloneWiki(ctx context.Context, u *user_model.User, opts migration.MigrateOp return "", err } - wikiRepo, err := git.OpenRepository(ctx, wikiPath) - if err != nil { - cleanIncompleteWikiPath() - return "", fmt.Errorf("failed to open wiki repo %q, err: %w", wikiPath, err) - } - defer wikiRepo.Close() - - defaultBranch, err := wikiRepo.GetDefaultBranch() + defaultBranch, err := git.GetDefaultBranch(ctx, wikiPath) if err != nil { cleanIncompleteWikiPath() return "", fmt.Errorf("failed to get wiki repo default branch for %q, err: %w", wikiPath, err) diff --git a/services/repository/push.go b/services/repository/push.go index 89a3127902..0aeb4c830b 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -182,7 +182,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { repo.DefaultBranch = refName repo.IsEmpty = false if repo.DefaultBranch != setting.Repository.DefaultBranch { - if err := gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil { + if err := gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil { if !git.IsErrUnsupportedVersion(err) { return err } |