Implemented rebase strategy
1 parent a03d1c9 commit fcb374c5c29fb873ec426e63afbf1b0b473fcd1c
@Naoki Takezoe Naoki Takezoe authored on 10 Dec 2017
Showing 3 changed files
View
24
src/main/scala/gitbucket/core/controller/PullRequestsController.scala
recordMergeActivity(owner, name, loginAccount.userName, issueId, form.message)
 
// 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
17
src/main/scala/gitbucket/core/service/MergeService.scala
new MergeCacheInfo(git, branch, issueId).checkConflictCache()
}
}
 
/** 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){
// update refs
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
2
■■■
src/main/twirl/gitbucket/core/pulls/mergeguide.scala.html
}
 
$('.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>