|
@@ -215,11 +215,13 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
|
|
return fmt.Errorf("OpenRepository: %v", err)
|
|
return fmt.Errorf("OpenRepository: %v", err)
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
+
|
|
tmpBasePath := path.Join(setting.AppDataPath, "tmp/repos", com.ToStr(time.Now().Nanosecond())+".git")
|
|
tmpBasePath := path.Join(setting.AppDataPath, "tmp/repos", com.ToStr(time.Now().Nanosecond())+".git")
|
|
os.MkdirAll(path.Dir(tmpBasePath), os.ModePerm)
|
|
os.MkdirAll(path.Dir(tmpBasePath), os.ModePerm)
|
|
defer os.RemoveAll(path.Dir(tmpBasePath))
|
|
defer os.RemoveAll(path.Dir(tmpBasePath))
|
|
|
|
|
|
|
|
+
|
|
var stderr string
|
|
var stderr string
|
|
if _, stderr, err = process.ExecTimeout(5*time.Minute,
|
|
if _, stderr, err = process.ExecTimeout(5*time.Minute,
|
|
fmt.Sprintf("PullRequest.Merge (git clone): %s", tmpBasePath),
|
|
fmt.Sprintf("PullRequest.Merge (git clone): %s", tmpBasePath),
|
|
@@ -227,26 +229,22 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
|
|
return fmt.Errorf("git clone: %s", stderr)
|
|
return fmt.Errorf("git clone: %s", stderr)
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
- if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
|
- fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
|
|
|
|
- "git", "checkout", pr.BaseBranch); err != nil {
|
|
|
|
- return fmt.Errorf("git checkout: %s", stderr)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
fmt.Sprintf("PullRequest.Merge (git remote add): %s", tmpBasePath),
|
|
fmt.Sprintf("PullRequest.Merge (git remote add): %s", tmpBasePath),
|
|
"git", "remote", "add", "head_repo", headRepoPath); err != nil {
|
|
"git", "remote", "add", "head_repo", headRepoPath); err != nil {
|
|
return fmt.Errorf("git remote add [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
|
|
return fmt.Errorf("git remote add [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
fmt.Sprintf("PullRequest.Merge (git fetch): %s", tmpBasePath),
|
|
fmt.Sprintf("PullRequest.Merge (git fetch): %s", tmpBasePath),
|
|
"git", "fetch", "head_repo"); err != nil {
|
|
"git", "fetch", "head_repo"); err != nil {
|
|
return fmt.Errorf("git fetch [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
|
|
return fmt.Errorf("git fetch [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ remoteHeadBranch := "head_repo/" + pr.HeadBranch
|
|
|
|
+
|
|
|
|
|
|
if mergeStyle == MERGE_STYLE_REBASE && !pr.BaseRepo.PullsAllowRebase {
|
|
if mergeStyle == MERGE_STYLE_REBASE && !pr.BaseRepo.PullsAllowRebase {
|
|
mergeStyle = MERGE_STYLE_REGULAR
|
|
mergeStyle = MERGE_STYLE_REGULAR
|
|
@@ -254,12 +252,22 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
|
|
|
|
|
|
switch mergeStyle {
|
|
switch mergeStyle {
|
|
case MERGE_STYLE_REGULAR:
|
|
case MERGE_STYLE_REGULAR:
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
|
+ fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
|
|
|
|
+ "git", "checkout", pr.BaseBranch); err != nil {
|
|
|
|
+ return fmt.Errorf("git checkout '%s': %s", pr.BaseBranch, stderr)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
fmt.Sprintf("PullRequest.Merge (git merge --no-ff --no-commit): %s", 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 {
|
|
+ "git", "merge", "--no-ff", "--no-commit", remoteHeadBranch); err != nil {
|
|
return fmt.Errorf("git merge --no-ff --no-commit [%s]: %v - %s", tmpBasePath, err, stderr)
|
|
return fmt.Errorf("git merge --no-ff --no-commit [%s]: %v - %s", tmpBasePath, err, stderr)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
sig := doer.NewGitSig()
|
|
sig := doer.NewGitSig()
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
fmt.Sprintf("PullRequest.Merge (git merge): %s", tmpBasePath),
|
|
fmt.Sprintf("PullRequest.Merge (git merge): %s", tmpBasePath),
|
|
@@ -269,17 +277,41 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
|
|
}
|
|
}
|
|
|
|
|
|
case MERGE_STYLE_REBASE:
|
|
case MERGE_STYLE_REBASE:
|
|
|
|
+
|
|
|
|
+
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
fmt.Sprintf("PullRequest.Merge (git rebase): %s", tmpBasePath),
|
|
fmt.Sprintf("PullRequest.Merge (git rebase): %s", tmpBasePath),
|
|
- "git", "rebase", "-q", pr.BaseBranch, "head_repo/"+pr.HeadBranch); err != nil {
|
|
+ "git", "rebase", "--quiet", pr.BaseBranch, remoteHeadBranch); err != nil {
|
|
- return fmt.Errorf("git rebase [%s -> %s]: %s", headRepoPath, tmpBasePath, stderr)
|
|
+ return fmt.Errorf("git rebase [%s on %s]: %s", remoteHeadBranch, pr.BaseBranch, stderr)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ tmpBranch := com.ToStr(time.Now().UnixNano(), 10)
|
|
|
|
+ if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
|
+ fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
|
|
|
|
+ "git", "checkout", "-b", tmpBranch); err != nil {
|
|
|
|
+ return fmt.Errorf("git checkout '%s': %s", tmpBranch, stderr)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
|
+ fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
|
|
|
|
+ "git", "checkout", pr.BaseBranch); err != nil {
|
|
|
|
+ return fmt.Errorf("git checkout '%s': %s", pr.BaseBranch, stderr)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
|
|
+ fmt.Sprintf("PullRequest.Merge (git merge): %s", tmpBasePath),
|
|
|
|
+ "git", "merge", tmpBranch); err != nil {
|
|
|
|
+ return fmt.Errorf("git merge [%s]: %v - %s", tmpBasePath, err, stderr)
|
|
}
|
|
}
|
|
|
|
|
|
default:
|
|
default:
|
|
return fmt.Errorf("unknown merge style: %s", mergeStyle)
|
|
return fmt.Errorf("unknown merge style: %s", mergeStyle)
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
|
|
fmt.Sprintf("PullRequest.Merge (git push): %s", tmpBasePath),
|
|
fmt.Sprintf("PullRequest.Merge (git push): %s", tmpBasePath),
|
|
"git", "push", baseGitRepo.Path, pr.BaseBranch); err != nil {
|
|
"git", "push", baseGitRepo.Path, pr.BaseBranch); err != nil {
|