loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix loadOneBranch panic (#29938)

Try to fix #29936

Far from ideal, but still better than panic.

(cherry picked from commit 21151474e36eecc5b808963b924cd27ec34e0608)

authored by

wxiaoguang and committed by
Earl Warren
0710de9d 165182a9

+7 -5
+1 -1
modules/git/repo.go
··· 283 283 // GetDivergingCommits returns the number of commits a targetBranch is ahead or behind a baseBranch 284 284 func GetDivergingCommits(ctx context.Context, repoPath, baseBranch, targetBranch string) (do DivergeObject, err error) { 285 285 cmd := NewCommand(ctx, "rev-list", "--count", "--left-right"). 286 - AddDynamicArguments(baseBranch + "..." + targetBranch) 286 + AddDynamicArguments(baseBranch + "..." + targetBranch).AddArguments("--") 287 287 stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath}) 288 288 if err != nil { 289 289 return do, err
+6 -4
services/repository/branch.go
··· 127 127 p := protectedBranches.GetFirstMatched(branchName) 128 128 isProtected := p != nil 129 129 130 - divergence := &git.DivergeObject{ 131 - Ahead: -1, 132 - Behind: -1, 133 - } 130 + var divergence *git.DivergeObject 134 131 135 132 // it's not default branch 136 133 if repo.DefaultBranch != dbBranch.Name && !dbBranch.IsDeleted { ··· 139 136 if err != nil { 140 137 return nil, fmt.Errorf("CountDivergingCommits: %v", err) 141 138 } 139 + } 140 + 141 + if divergence == nil { 142 + // tolerate the error that we cannot get divergence 143 + divergence = &git.DivergeObject{Ahead: -1, Behind: -1} 142 144 } 143 145 144 146 pr, err := issues_model.GetLatestPullRequestByHeadInfo(ctx, repo.ID, branchName)