Skip to content

Commit fb056bf

Browse files
authored
Use gitrepo.SetDefaultBranch when set default branch of wiki repository (#33911)
1 parent 7636d58 commit fb056bf

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

routers/api/v1/repo/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,14 +736,14 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
736736
// Default branch only updated if changed and exist or the repository is empty
737737
updateRepoLicense := false
738738
if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, *opts.DefaultBranch)) {
739+
repo.DefaultBranch = *opts.DefaultBranch
739740
if !repo.IsEmpty {
740-
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, *opts.DefaultBranch); err != nil {
741+
if err := gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
741742
ctx.APIErrorInternal(err)
742743
return err
743744
}
744745
updateRepoLicense = true
745746
}
746-
repo.DefaultBranch = *opts.DefaultBranch
747747
}
748748

749749
if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil {

services/wiki/wiki.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
4343
return fmt.Errorf("InitRepository: %w", err)
4444
} else if err = gitrepo.CreateDelegateHooks(ctx, repo.WikiStorageRepo()); err != nil {
4545
return fmt.Errorf("createDelegateHooks: %w", err)
46-
} else if _, _, err = git.NewCommand("symbolic-ref", "HEAD").AddDynamicArguments(git.BranchPrefix+repo.DefaultWikiBranch).RunStdString(ctx, &git.RunOpts{Dir: repo.WikiPath()}); err != nil {
46+
} else if err = gitrepo.SetDefaultBranch(ctx, repo.WikiStorageRepo(), repo.DefaultWikiBranch); err != nil {
4747
return fmt.Errorf("unable to set default wiki branch to %q: %w", repo.DefaultWikiBranch, err)
4848
}
4949
return nil

0 commit comments

Comments
 (0)