summaryrefslogtreecommitdiffstats
path: root/models/pull.go
diff options
context:
space:
mode:
authorJulian <julian.toelle97@gmail.com>2018-12-27 11:27:08 +0100
committerLauris BH <lauris@nix.lv>2018-12-27 12:27:08 +0200
commit4a685f8b872a3d4c101c5e8165fa99e696c8fb45 (patch)
tree7ad36ee9bf87cec61ee0967a50037d9331d2ab58 /models/pull.go
parent58bdff53cd98e33791f91584d02887864aabc5c4 (diff)
downloadgitea-4a685f8b872a3d4c101c5e8165fa99e696c8fb45.tar.gz
gitea-4a685f8b872a3d4c101c5e8165fa99e696c8fb45.zip
Add rebase with merge commit merge style (#3844) (#4052)
Signed-off-by: Julian Tölle <julian.toelle97@gmail.com>
Diffstat (limited to 'models/pull.go')
-rw-r--r--models/pull.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/models/pull.go b/models/pull.go
index 4c4c3f3e1e..cd21e494a2 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -297,6 +297,8 @@ const (
MergeStyleMerge MergeStyle = "merge"
// MergeStyleRebase rebase before merging
MergeStyleRebase MergeStyle = "rebase"
+ // MergeStyleRebaseMerge rebase before merging with merge commit (--no-ff)
+ MergeStyleRebaseMerge MergeStyle = "rebase-merge"
// MergeStyleSquash squash commits into single commit before merging
MergeStyleSquash MergeStyle = "squash"
)
@@ -434,6 +436,41 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
"git", "merge", "--ff-only", "-q", "head_repo_"+pr.HeadBranch); err != nil {
return fmt.Errorf("git merge --ff-only [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
}
+ case MergeStyleRebaseMerge:
+ // Checkout head branch
+ if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
+ fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
+ "git", "checkout", "-b", "head_repo_"+pr.HeadBranch, "head_repo/"+pr.HeadBranch); err != nil {
+ return fmt.Errorf("git checkout: %s", stderr)
+ }
+ // Rebase before merging
+ if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
+ fmt.Sprintf("PullRequest.Merge (git rebase): %s", tmpBasePath),
+ "git", "rebase", "-q", pr.BaseBranch); err != nil {
+ return fmt.Errorf("git rebase [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
+ }
+ // Checkout base branch again
+ if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
+ fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
+ "git", "checkout", pr.BaseBranch); err != nil {
+ return fmt.Errorf("git checkout: %s", stderr)
+ }
+ // Prepare merge with commit
+ if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
+ fmt.Sprintf("PullRequest.Merge (git merge): %s", tmpBasePath),
+ "git", "merge", "--no-ff", "--no-commit", "-q", "head_repo_"+pr.HeadBranch); err != nil {
+ return fmt.Errorf("git merge --no-ff [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
+ }
+
+ // Set custom message and author and create merge commit
+ sig := doer.NewGitSig()
+ if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,
+ fmt.Sprintf("PullRequest.Merge (git commit): %s", tmpBasePath),
+ "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
+ "-m", message); err != nil {
+ return fmt.Errorf("git commit [%s]: %v - %s", tmpBasePath, err, stderr)
+ }
+
case MergeStyleSquash:
// Merge with squash
if _, stderr, err = process.GetManager().ExecDir(-1, tmpBasePath,