@@ -2831,53 +2831,55 @@ func NewComment(ctx *context.Context) {
28312831
28322832 // check whether the ref of PR <refs/pulls/pr_index/head> in base repo is consistent with the head commit of head branch in the head repo
28332833 // get head commit of PR
2834- prHeadRef := pull .GetGitRefName ()
2835- if err := pull .LoadBaseRepo (ctx ); err != nil {
2836- ctx .ServerError ("Unable to load base repo" , err )
2837- return
2838- }
2839- prHeadCommitID , err := git .GetFullCommitID (ctx , pull .BaseRepo .RepoPath (), prHeadRef )
2840- if err != nil {
2841- ctx .ServerError ("Get head commit Id of pr fail" , err )
2842- return
2843- }
2844-
2845- // get head commit of branch in the head repo
2846- if err := pull .LoadHeadRepo (ctx ); err != nil {
2847- ctx .ServerError ("Unable to load head repo" , err )
2848- return
2849- }
2850- if ok := git .IsBranchExist (ctx , pull .HeadRepo .RepoPath (), pull .BaseBranch ); ! ok {
2851- // todo localize
2852- ctx .Flash .Error ("The origin branch is delete, cannot reopen." )
2853- ctx .Redirect (fmt .Sprintf ("%s/pulls/%d" , ctx .Repo .RepoLink , pull .Index ))
2854- return
2855- }
2856- headBranchRef := pull .GetGitHeadBranchRefName ()
2857- headBranchCommitID , err := git .GetFullCommitID (ctx , pull .HeadRepo .RepoPath (), headBranchRef )
2858- if err != nil {
2859- ctx .ServerError ("Get head commit Id of head branch fail" , err )
2860- return
2861- }
2834+ if pull .Flow == issues_model .PullRequestFlowGithub {
2835+ prHeadRef := pull .GetGitRefName ()
2836+ if err := pull .LoadBaseRepo (ctx ); err != nil {
2837+ ctx .ServerError ("Unable to load base repo" , err )
2838+ return
2839+ }
2840+ prHeadCommitID , err := git .GetFullCommitID (ctx , pull .BaseRepo .RepoPath (), prHeadRef )
2841+ if err != nil {
2842+ ctx .ServerError ("Get head commit Id of pr fail" , err )
2843+ return
2844+ }
28622845
2863- err = pull .LoadIssue (ctx )
2864- if err != nil {
2865- ctx .ServerError ("load the issue of pull request error" , err )
2866- return
2867- }
2846+ // get head commit of branch in the head repo
2847+ if err := pull .LoadHeadRepo (ctx ); err != nil {
2848+ ctx .ServerError ("Unable to load head repo" , err )
2849+ return
2850+ }
2851+ if ok := git .IsBranchExist (ctx , pull .HeadRepo .RepoPath (), pull .BaseBranch ); ! ok {
2852+ // todo localize
2853+ ctx .Flash .Error ("The origin branch is delete, cannot reopen." )
2854+ ctx .Redirect (fmt .Sprintf ("%s/pulls/%d" , ctx .Repo .RepoLink , pull .Index ))
2855+ return
2856+ }
2857+ headBranchRef := pull .GetGitHeadBranchRefName ()
2858+ headBranchCommitID , err := git .GetFullCommitID (ctx , pull .HeadRepo .RepoPath (), headBranchRef )
2859+ if err != nil {
2860+ ctx .ServerError ("Get head commit Id of head branch fail" , err )
2861+ return
2862+ }
28682863
2869- if prHeadCommitID != headBranchCommitID {
2870- // force push to base repo
2871- err := git .Push (ctx , pull .HeadRepo .RepoPath (), git.PushOptions {
2872- Remote : pull .BaseRepo .RepoPath (),
2873- Branch : pull .HeadBranch + ":" + prHeadRef ,
2874- Force : true ,
2875- Env : repo_module .InternalPushingEnvironment (pull .Issue .Poster , pull .BaseRepo ),
2876- })
2864+ err = pull .LoadIssue (ctx )
28772865 if err != nil {
2878- ctx .ServerError ("force push error" , err )
2866+ ctx .ServerError ("load the issue of pull request error" , err )
28792867 return
28802868 }
2869+
2870+ if prHeadCommitID != headBranchCommitID {
2871+ // force push to base repo
2872+ err := git .Push (ctx , pull .HeadRepo .RepoPath (), git.PushOptions {
2873+ Remote : pull .BaseRepo .RepoPath (),
2874+ Branch : pull .HeadBranch + ":" + prHeadRef ,
2875+ Force : true ,
2876+ Env : repo_module .InternalPushingEnvironment (pull .Issue .Poster , pull .BaseRepo ),
2877+ })
2878+ if err != nil {
2879+ ctx .ServerError ("force push error" , err )
2880+ return
2881+ }
2882+ }
28812883 }
28822884 }
28832885
0 commit comments