mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-04 08:17:24 -05:00
fix reopen logic for agit flow pull request (#26399)
the head branch is meaningless for a agit flow pull request, so should not check it when reopen it. related: #24231 fix #26334 Signed-off-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
parent
5feef6d5c0
commit
f00fdd1abd
@ -2935,52 +2935,54 @@ func NewComment(ctx *context.Context) {
|
|||||||
|
|
||||||
// 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
|
// 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
|
||||||
// get head commit of PR
|
// get head commit of PR
|
||||||
prHeadRef := pull.GetGitRefName()
|
if pull.Flow == issues_model.PullRequestFlowGithub {
|
||||||
if err := pull.LoadBaseRepo(ctx); err != nil {
|
prHeadRef := pull.GetGitRefName()
|
||||||
ctx.ServerError("Unable to load base repo", err)
|
if err := pull.LoadBaseRepo(ctx); err != nil {
|
||||||
return
|
ctx.ServerError("Unable to load base repo", err)
|
||||||
}
|
|
||||||
prHeadCommitID, err := git.GetFullCommitID(ctx, pull.BaseRepo.RepoPath(), prHeadRef)
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("Get head commit Id of pr fail", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// get head commit of branch in the head repo
|
|
||||||
if err := pull.LoadHeadRepo(ctx); err != nil {
|
|
||||||
ctx.ServerError("Unable to load head repo", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ok := git.IsBranchExist(ctx, pull.HeadRepo.RepoPath(), pull.BaseBranch); !ok {
|
|
||||||
// todo localize
|
|
||||||
ctx.JSONError("The origin branch is delete, cannot reopen.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
headBranchRef := pull.GetGitHeadBranchRefName()
|
|
||||||
headBranchCommitID, err := git.GetFullCommitID(ctx, pull.HeadRepo.RepoPath(), headBranchRef)
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("Get head commit Id of head branch fail", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = pull.LoadIssue(ctx)
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("load the issue of pull request error", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if prHeadCommitID != headBranchCommitID {
|
|
||||||
// force push to base repo
|
|
||||||
err := git.Push(ctx, pull.HeadRepo.RepoPath(), git.PushOptions{
|
|
||||||
Remote: pull.BaseRepo.RepoPath(),
|
|
||||||
Branch: pull.HeadBranch + ":" + prHeadRef,
|
|
||||||
Force: true,
|
|
||||||
Env: repo_module.InternalPushingEnvironment(pull.Issue.Poster, pull.BaseRepo),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ctx.ServerError("force push error", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
prHeadCommitID, err := git.GetFullCommitID(ctx, pull.BaseRepo.RepoPath(), prHeadRef)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("Get head commit Id of pr fail", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// get head commit of branch in the head repo
|
||||||
|
if err := pull.LoadHeadRepo(ctx); err != nil {
|
||||||
|
ctx.ServerError("Unable to load head repo", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ok := git.IsBranchExist(ctx, pull.HeadRepo.RepoPath(), pull.BaseBranch); !ok {
|
||||||
|
// todo localize
|
||||||
|
ctx.JSONError("The origin branch is delete, cannot reopen.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
headBranchRef := pull.GetGitHeadBranchRefName()
|
||||||
|
headBranchCommitID, err := git.GetFullCommitID(ctx, pull.HeadRepo.RepoPath(), headBranchRef)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("Get head commit Id of head branch fail", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = pull.LoadIssue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("load the issue of pull request error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if prHeadCommitID != headBranchCommitID {
|
||||||
|
// force push to base repo
|
||||||
|
err := git.Push(ctx, pull.HeadRepo.RepoPath(), git.PushOptions{
|
||||||
|
Remote: pull.BaseRepo.RepoPath(),
|
||||||
|
Branch: pull.HeadBranch + ":" + prHeadRef,
|
||||||
|
Force: true,
|
||||||
|
Env: repo_module.InternalPushingEnvironment(pull.Issue.Poster, pull.BaseRepo),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("force push error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user