Move get/set default branch from git package to gitrepo package to hide repopath (#29126)
This commit is contained in:
parent
a1f5dd7677
commit
25b842df26
15 changed files with 52 additions and 63 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue