diff options
author | a1012112796 <1012112796@qq.com> | 2021-08-31 22:03:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-31 16:03:45 +0200 |
commit | cbf05c3f795c1eed999dafe8d0757495e07f1ee2 (patch) | |
tree | e9b227ef8dd8d836b04bd126806c8a1264b750ee /services/pull/merge.go | |
parent | 2bb32006fd560af44426a06f63f83e3c70c3f258 (diff) | |
download | gitea-cbf05c3f795c1eed999dafe8d0757495e07f1ee2.tar.gz gitea-cbf05c3f795c1eed999dafe8d0757495e07f1ee2.zip |
Add option to update pull request by `rebase` (#16125)
* add option to update pull request by `rebase`
Signed-off-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'services/pull/merge.go')
-rw-r--r-- | services/pull/merge.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/services/pull/merge.go b/services/pull/merge.go index 7e6a214b87..ef797e1ca4 100644 --- a/services/pull/merge.go +++ b/services/pull/merge.go @@ -253,6 +253,8 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge } case models.MergeStyleRebase: fallthrough + case models.MergeStyleRebaseUpdate: + fallthrough case models.MergeStyleRebaseMerge: // Checkout head branch if err := git.NewCommand("checkout", "-b", stagingBranch, trackingBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil { @@ -305,6 +307,11 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge outbuf.Reset() errbuf.Reset() + // not need merge, just update by rebase. so skip + if mergeStyle == models.MergeStyleRebaseUpdate { + break + } + // Checkout base branch again if err := git.NewCommand("checkout", baseBranch).RunInDirPipeline(tmpBasePath, &outbuf, &errbuf); err != nil { log.Error("git checkout base prior to merge post staging rebase [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String()) @@ -410,8 +417,16 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge pr.ID, ) + var pushCmd *git.Command + if mergeStyle == models.MergeStyleRebaseUpdate { + // force push the rebase result to head brach + pushCmd = git.NewCommand("push", "-f", "head_repo", stagingBranch+":refs/heads/"+pr.HeadBranch) + } else { + pushCmd = git.NewCommand("push", "origin", baseBranch+":refs/heads/"+pr.BaseBranch) + } + // Push back to upstream. - if err := git.NewCommand("push", "origin", baseBranch+":refs/heads/"+pr.BaseBranch).RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, &outbuf, &errbuf); err != nil { + if err := pushCmd.RunInDirTimeoutEnvPipeline(env, -1, tmpBasePath, &outbuf, &errbuf); err != nil { if strings.Contains(errbuf.String(), "non-fast-forward") { return "", &git.ErrPushOutOfDate{ StdOut: outbuf.String(), |