1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-13 22:17:20 +00:00

Move get/set default branch from git package to gitrepo package to hide repopath (#29126)

This commit is contained in:
Lunny Xiao
2024-03-08 15:30:10 +08:00
committed by GitHub
parent a1f5dd7677
commit 25b842df26
15 changed files with 52 additions and 63 deletions

View File

@ -370,6 +370,14 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n
return fmt.Errorf("unable to update database: %w", err)
}
oldDefBranch, err := gitrepo.GetWikiDefaultBranch(ctx, repo)
if err != nil {
return fmt.Errorf("unable to get default branch: %w", err)
}
if oldDefBranch == newBranch {
return nil
}
gitRepo, err := gitrepo.OpenWikiRepository(ctx, repo)
if errors.Is(err, util.ErrNotExist) {
return nil // no git repo on storage, no need to do anything else
@ -378,14 +386,6 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n
}
defer gitRepo.Close()
oldDefBranch, err := gitRepo.GetDefaultBranch()
if err != nil {
return fmt.Errorf("unable to get default branch: %w", err)
}
if oldDefBranch == newBranch {
return nil
}
err = gitRepo.RenameBranch(oldDefBranch, newBranch)
if err != nil {
return fmt.Errorf("unable to rename default branch: %w", err)