Skip to content

Commit 1fccf00

Browse files
authored
Merge branch 'main' into lunny/move_wikipath
2 parents 67e7a1e + fb056bf commit 1fccf00

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
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/repository/branch.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
532532
// database branch record not exist or it's a deleted branch
533533
notExist := git_model.IsErrBranchNotExist(err) || rawBranch.IsDeleted
534534

535-
commit, err := gitRepo.GetBranchCommit(branchName)
536-
if err != nil {
535+
branchCommit, err := gitRepo.GetBranchCommit(branchName)
536+
if err != nil && !errors.Is(err, util.ErrNotExist) {
537537
return err
538538
}
539539

@@ -549,6 +549,9 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
549549
return fmt.Errorf("DeleteBranch: %v", err)
550550
}
551551
}
552+
if branchCommit == nil {
553+
return nil
554+
}
552555

553556
return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
554557
Force: true,
@@ -557,20 +560,24 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
557560
return err
558561
}
559562

560-
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
563+
if branchCommit == nil {
564+
return nil
565+
}
561566

562567
// Don't return error below this
568+
569+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
563570
if err := PushUpdate(
564571
&repo_module.PushUpdateOptions{
565572
RefFullName: git.RefNameFromBranch(branchName),
566-
OldCommitID: commit.ID.String(),
573+
OldCommitID: branchCommit.ID.String(),
567574
NewCommitID: objectFormat.EmptyObjectID().String(),
568575
PusherID: doer.ID,
569576
PusherName: doer.Name,
570577
RepoUserName: repo.OwnerName,
571578
RepoName: repo.Name,
572579
}); err != nil {
573-
log.Error("Update: %v", err)
580+
log.Error("PushUpdateOptions: %v", err)
574581
}
575582

576583
return nil

services/wiki/wiki.go

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

0 commit comments

Comments
 (0)