Skip to content

Commit d2938ed

Browse files
committed
fix
1 parent 8cad44f commit d2938ed

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

modules/git/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ type DivergeObject struct {
283283
// GetDivergingCommits returns the number of commits a targetBranch is ahead or behind a baseBranch
284284
func GetDivergingCommits(ctx context.Context, repoPath, baseBranch, targetBranch string) (do DivergeObject, err error) {
285285
cmd := NewCommand(ctx, "rev-list", "--count", "--left-right").
286-
AddDynamicArguments(baseBranch + "..." + targetBranch)
286+
AddDynamicArguments(baseBranch + "..." + targetBranch).AddArguments("--")
287287
stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath})
288288
if err != nil {
289289
return do, err

services/repository/branch.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
158158
p := protectedBranches.GetFirstMatched(branchName)
159159
isProtected := p != nil
160160

161-
divergence := &git.DivergeObject{
162-
Ahead: -1,
163-
Behind: -1,
164-
}
161+
var divergence *git.DivergeObject
165162

166163
// it's not default branch
167164
if repo.DefaultBranch != dbBranch.Name && !dbBranch.IsDeleted {
@@ -180,6 +177,11 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
180177
}
181178
}
182179

180+
if divergence == nil {
181+
// tolerate the error that we cannot get divergence
182+
divergence = &git.DivergeObject{Ahead: -1, Behind: -1}
183+
}
184+
183185
pr, err := issues_model.GetLatestPullRequestByHeadInfo(ctx, repo.ID, branchName)
184186
if err != nil {
185187
return nil, fmt.Errorf("GetLatestPullRequestByHeadInfo: %v", err)

0 commit comments

Comments
 (0)