Implemented rebase strategy

This commit is contained in:
Naoki Takezoe
2017-12-10 18:04:45 +09:00
parent a03d1c97c2
commit fcb374c5c2
3 changed files with 28 additions and 6 deletions

View File

@@ -261,9 +261,18 @@ trait PullRequestsControllerBase extends ControllerBase {
// merge git repository
// TODO Implement merge strategy!
mergePullRequest(git, pullreq.branch, issueId,
s"Merge pull request #${issueId} from ${pullreq.requestUserName}/${pullreq.requestBranch}\n\n" + form.message,
new PersonIdent(loginAccount.fullName, loginAccount.mailAddress))
println(form.strategy)
form.strategy match {
case "merge-commit" =>
println("** merge commit **")
mergePullRequest(git, pullreq.branch, issueId,
s"Merge pull request #${issueId} from ${pullreq.requestUserName}/${pullreq.requestBranch}\n\n" + form.message,
new PersonIdent(loginAccount.fullName, loginAccount.mailAddress))
case "rebase" =>
println("** rebase **")
rebasePullRequest(git, pullreq.branch, issueId,
new PersonIdent(loginAccount.fullName, loginAccount.mailAddress))
}
val (commits, _) = getRequestCompareInfo(owner, name, pullreq.commitIdFrom,
pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.commitIdTo)

View File

@@ -35,11 +35,16 @@ trait MergeService {
}
}
/** merge pull request */
def mergePullRequest(git:Git, branch: String, issueId: Int, message:String, committer: PersonIdent): Unit = {
/** merge the pull request with a merge commit */
def mergePullRequest(git: Git, branch: String, issueId: Int, message: String, committer: PersonIdent): Unit = {
new MergeCacheInfo(git, branch, issueId).merge(message, committer)
}
/** rebase to the pull request branch */
def rebasePullRequest(git: Git, branch: String, issueId: Int, committer: PersonIdent): Unit = {
new MergeCacheInfo(git, branch, issueId).rebase(committer)
}
/** fetch remote branch to my repository refs/pull/{issueId}/head */
def fetchAsPullRequest(userName: String, repositoryName: String, requestUserName: String, requestRepositoryName: String, requestBranch:String, issueId:Int){
using(Git.open(getRepositoryDir(userName, repositoryName))){ git =>
@@ -209,6 +214,14 @@ object MergeService{
Util.updateRefs(repository, s"refs/heads/${branch}", mergeCommitId, false, committer, Some("merged"))
}
def rebase(committer: PersonIdent) = {
if(checkConflict()){
throw new RuntimeException("This pull request can't merge automatically.")
}
val mergeTipCommit = using(new RevWalk( repository ))(_.parseCommit( mergeTip ))
Util.updateRefs(repository, s"refs/heads/${branch}", mergeTipCommit.getId, false, committer, Some("merged"))
}
// return treeId
private def createMergeCommit(treeId: ObjectId, committer: PersonIdent, message: String) =
Util.createMergeCommit(repository, treeId, committer, message, Seq[ObjectId](mergeBaseTip, mergeTip))

View File

@@ -223,7 +223,7 @@ $(function(){
$('.merge-strategy').click(function(){
$('button#merge-strategy-btn > span.strong').text($(this).find('strong').text());
$('hidden[name=strategy]').val($(this).data('value'));
$('input[name=strategy]').val($(this).data('value'));
});
});
</script>