diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-03-20 23:38:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-20 15:38:22 +0000 |
commit | 21151474e36eecc5b808963b924cd27ec34e0608 (patch) | |
tree | e3b39a71923a60fa42a5b09043b6aeda96cb3833 /services | |
parent | bc55a80693aded26efd856812097536e2402d491 (diff) | |
download | gitea-21151474e36eecc5b808963b924cd27ec34e0608.tar.gz gitea-21151474e36eecc5b808963b924cd27ec34e0608.zip |
Fix loadOneBranch panic (#29938)
Try to fix #29936
Far from ideal, but still better than panic.
Diffstat (limited to 'services')
-rw-r--r-- | services/repository/branch.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/services/repository/branch.go b/services/repository/branch.go index db7acdb505..0353c75fe9 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -158,10 +158,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g p := protectedBranches.GetFirstMatched(branchName) isProtected := p != nil - divergence := &git.DivergeObject{ - Ahead: -1, - Behind: -1, - } + var divergence *git.DivergeObject // it's not default branch if repo.DefaultBranch != dbBranch.Name && !dbBranch.IsDeleted { @@ -180,6 +177,11 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g } } + if divergence == nil { + // tolerate the error that we cannot get divergence + divergence = &git.DivergeObject{Ahead: -1, Behind: -1} + } + pr, err := issues_model.GetLatestPullRequestByHeadInfo(ctx, repo.ID, branchName) if err != nil { return nil, fmt.Errorf("GetLatestPullRequestByHeadInfo: %v", err) |