|
@@ -233,31 +233,40 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
|
|
|
return fmt.Errorf("git remote add [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
|
|
|
}
|
|
|
|
|
|
- // Merge commits.
|
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
fmt.Sprintf("PullRequest.Merge (git fetch): %s", tmpBasePath),
|
|
|
"git", "fetch", "head_repo"); err != nil {
|
|
|
return fmt.Errorf("git fetch [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
|
|
|
}
|
|
|
|
|
|
- if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
- fmt.Sprintf("PullRequest.Merge (git merge --no-ff --no-commit): %s", tmpBasePath),
|
|
|
- "git", "merge", "--no-ff", "--no-commit", "head_repo/"+pr.HeadBranch); err != nil {
|
|
|
- return fmt.Errorf("git merge --no-ff --no-commit [%s]: %v - %s", tmpBasePath, err, stderr)
|
|
|
- }
|
|
|
+ if (pr.BaseRepo.PullUseRebase) {
|
|
|
+ // Rebase.
|
|
|
+ if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
+ fmt.Sprintf("PullRequest.Rebase (git rebase): %s", tmpBasePath),
|
|
|
+ "git", "rebase", "-q", pr.BaseBranch, "head_repo/"+pr.HeadBranch); err != nil {
|
|
|
+ return fmt.Errorf("git rebase [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // Merge commits.
|
|
|
+ if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
+ fmt.Sprintf("PullRequest.Merge (git merge --no-ff --no-commit): %s", tmpBasePath),
|
|
|
+ "git", "merge", "--no-ff", "--no-commit", "head_repo/"+pr.HeadBranch); err != nil {
|
|
|
+ return fmt.Errorf("git merge --no-ff --no-commit [%s]: %v - %s", tmpBasePath, err, stderr)
|
|
|
+ }
|
|
|
|
|
|
- sig := doer.NewGitSig()
|
|
|
- if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
- fmt.Sprintf("PullRequest.Merge (git merge): %s", tmpBasePath),
|
|
|
- "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
|
|
|
- "-m", fmt.Sprintf("Merge branch '%s' of %s/%s into %s", pr.HeadBranch, pr.HeadUserName, pr.HeadRepo.Name, pr.BaseBranch)); err != nil {
|
|
|
- return fmt.Errorf("git commit [%s]: %v - %s", tmpBasePath, err, stderr)
|
|
|
+ sig := doer.NewGitSig()
|
|
|
+ if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
+ fmt.Sprintf("PullRequest.Merge (git merge): %s", tmpBasePath),
|
|
|
+ "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
|
|
|
+ "-m", fmt.Sprintf("Merge branch '%s' of %s/%s into %s", pr.HeadBranch, pr.HeadUserName, pr.HeadRepo.Name, pr.BaseBranch)); err != nil {
|
|
|
+ return fmt.Errorf("git commit [%s]: %v - %s", tmpBasePath, err, stderr)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Push back to upstream.
|
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
fmt.Sprintf("PullRequest.Merge (git push): %s", tmpBasePath),
|
|
|
- "git", "push", baseGitRepo.Path, pr.BaseBranch); err != nil {
|
|
|
+ "git", "push", "head_repo", "HEAD:"+pr.BaseBranch); err != nil {
|
|
|
return fmt.Errorf("git push: %s", stderr)
|
|
|
}
|
|
|
|