@@ -150,13 +150,13 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
150150 }
151151 defer gitRepo .Close ()
152152
153- baseBranch , err = gitRepo . GetBranch ( pr .BaseBranch )
154- if err != nil && ! git . IsErrBranchNotExist ( err ) {
153+ exist , err := git_model . IsBranchExist ( ctx , pr . BaseRepoID , pr .BaseBranch )
154+ if err != nil {
155155 log .Error ("GetBranch[%s]: %v" , pr .BaseBranch , err )
156156 return nil
157157 }
158158
159- if err == nil {
159+ if exist {
160160 baseCommit , err = gitRepo .GetBranchCommit (pr .BaseBranch )
161161 if err != nil && ! git .IsErrNotExist (err ) {
162162 log .Error ("GetCommit[%s]: %v" , baseBranch , err )
@@ -196,8 +196,8 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
196196 }
197197 defer headGitRepo .Close ()
198198
199- headBranch , err = headGitRepo . GetBranch ( pr .HeadBranch )
200- if err != nil && ! git . IsErrBranchNotExist ( err ) {
199+ exist , err = git_model . IsBranchExist ( ctx , pr . HeadRepoID , pr .HeadBranch )
200+ if err != nil {
201201 log .Error ("GetBranch[%s]: %v" , pr .HeadBranch , err )
202202 return nil
203203 }
@@ -208,7 +208,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
208208 endCommitID string
209209 )
210210
211- if git . IsErrBranchNotExist ( err ) {
211+ if ! exist {
212212 headCommitID , err := headGitRepo .GetRefCommitID (apiPullRequest .Head .Ref )
213213 if err != nil && ! git .IsErrNotExist (err ) {
214214 log .Error ("GetCommit[%s]: %v" , pr .HeadBranch , err )
@@ -455,13 +455,13 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
455455 defer headGitRepo .Close ()
456456 }
457457
458- headBranch , err := headGitRepo . GetBranch ( pr .HeadBranch )
459- if err != nil && ! git . IsErrBranchNotExist ( err ) {
458+ exist , err := git_model . IsBranchExist ( ctx , pr . HeadRepoID , pr .HeadBranch )
459+ if err != nil {
460460 log .Error ("GetBranch[%s]: %v" , pr .HeadBranch , err )
461461 return nil , err
462462 }
463463
464- if git . IsErrBranchNotExist ( err ) {
464+ if ! exist {
465465 headCommitID , err := headGitRepo .GetRefCommitID (apiPullRequest .Head .Ref )
466466 if err != nil && ! git .IsErrNotExist (err ) {
467467 log .Error ("GetCommit[%s]: %v" , pr .HeadBranch , err )
@@ -473,7 +473,7 @@ func ToAPIPullRequests(ctx context.Context, baseRepo *repo_model.Repository, prs
473473 } else {
474474 commit , err := headGitRepo .GetBranchCommit (pr .HeadBranch )
475475 if err != nil && ! git .IsErrNotExist (err ) {
476- log .Error ("GetCommit[%s]: %v" , headBranch , err )
476+ log .Error ("GetCommit[%s]: %v" , pr . HeadBranch , err )
477477 return nil , err
478478 }
479479 if err == nil {
0 commit comments