mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 22:15:51 +01:00
(refs #94)The merge-guide is separated as HTML fragment and retrieve them by Ajax.
This commit is contained in:
@@ -76,19 +76,24 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
getMilestonesWithIssueCount(owner, name),
|
||||
commits,
|
||||
diffs,
|
||||
if(issue.closed){
|
||||
false
|
||||
} else {
|
||||
checkConflict(owner, name, pullreq.branch, owner, name, pullreq.requestBranch)
|
||||
},
|
||||
hasWritePermission(owner, name, context.loginAccount),
|
||||
repository,
|
||||
s"${baseUrl}${context.path}/git/${pullreq.requestUserName}/${pullreq.requestRepositoryName}.git")
|
||||
repository)
|
||||
}
|
||||
} getOrElse NotFound
|
||||
}
|
||||
})
|
||||
|
||||
ajaxGet("/:owner/:repository/pull/:id/mergeguide")(collaboratorsOnly { repository =>
|
||||
defining(repository.owner, repository.name, params("id").toInt){ case (owner, name, issueId) =>
|
||||
getPullRequest(owner, name, issueId) map { case(issue, pullreq) =>
|
||||
pulls.html.mergeguide(
|
||||
checkConflict(owner, name, pullreq.branch, owner, name, pullreq.requestBranch),
|
||||
pullreq,
|
||||
s"${baseUrl}${context.path}/git/${pullreq.requestUserName}/${pullreq.requestRepositoryName}.git")
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
post("/:owner/:repository/pull/:id/merge", mergeForm)(collaboratorsOnly { (form, repository) =>
|
||||
defining(repository.owner, repository.name, params("id").toInt){ case (owner, name, issueId) =>
|
||||
LockUtil.lock(s"${owner}/${name}/merge"){
|
||||
@@ -164,41 +169,6 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Checks whether conflict will be caused in merging.
|
||||
* Returns true if conflict will be caused.
|
||||
*/
|
||||
private def checkConflict(userName: String, repositoryName: String, branch: String,
|
||||
requestUserName: String, requestRepositoryName: String, requestBranch: String): Boolean = {
|
||||
// TODO Are there more quick way?
|
||||
LockUtil.lock(s"${userName}/${repositoryName}/merge-check"){
|
||||
val remote = getRepositoryDir(userName, repositoryName)
|
||||
val tmpdir = new java.io.File(getTemporaryDir(userName, repositoryName), "merge-check")
|
||||
if(tmpdir.exists()){
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
|
||||
val git = Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(branch).call
|
||||
try {
|
||||
git.checkout.setName(branch).call
|
||||
|
||||
git.fetch
|
||||
.setRemote(getRepositoryDir(requestUserName, requestRepositoryName).toURI.toString)
|
||||
.setRefSpecs(new RefSpec(s"refs/heads/${branch}:refs/heads/${requestBranch}")).call
|
||||
|
||||
val result = git.merge
|
||||
.include(git.getRepository.resolve("FETCH_HEAD"))
|
||||
.setCommit(false).call
|
||||
|
||||
result.getConflicts != null
|
||||
|
||||
} finally {
|
||||
git.getRepository.close
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get("/:owner/:repository/compare")(referrersOnly { forkedRepository =>
|
||||
(forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match {
|
||||
case (Some(originUserName), Some(originRepositoryName)) => {
|
||||
@@ -229,11 +199,11 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
val (forkedOwner, tmpForkedBranch) = parseCompareIdentifie(forked, repository.owner)
|
||||
|
||||
(getRepository(originOwner, repository.name, baseUrl),
|
||||
getRepository(forkedOwner, repository.name, baseUrl)) match {
|
||||
getRepository(forkedOwner, repository.name, baseUrl)) match {
|
||||
case (Some(originRepository), Some(forkedRepository)) => {
|
||||
using(
|
||||
Git.open(getRepositoryDir(originOwner, repository.name)),
|
||||
Git.open(getRepositoryDir(forkedOwner, repository.name))
|
||||
Git.open(getRepositoryDir(forkedOwner, repository.name))
|
||||
){ case (oldGit, newGit) =>
|
||||
val originBranch = JGitUtil.getDefaultBranch(oldGit, originRepository, tmpOriginBranch).get._2
|
||||
val forkedBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository, tmpForkedBranch).get._2
|
||||
@@ -259,7 +229,6 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
forkedBranch,
|
||||
oldId.getName,
|
||||
newId.getName,
|
||||
checkConflict(originOwner, repository.name, originBranch, forkedOwner, repository.name, forkedBranch),
|
||||
repository,
|
||||
originRepository,
|
||||
forkedRepository,
|
||||
@@ -270,6 +239,29 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
}
|
||||
})
|
||||
|
||||
ajaxGet("/:owner/:repository/compare/*...*/mergecheck")(collaboratorsOnly { repository =>
|
||||
val Seq(origin, forked) = multiParams("splat")
|
||||
val (originOwner, tmpOriginBranch) = parseCompareIdentifie(origin, repository.owner)
|
||||
val (forkedOwner, tmpForkedBranch) = parseCompareIdentifie(forked, repository.owner)
|
||||
|
||||
(getRepository(originOwner, repository.name, baseUrl),
|
||||
getRepository(forkedOwner, repository.name, baseUrl)) match {
|
||||
case (Some(originRepository), Some(forkedRepository)) => {
|
||||
using(
|
||||
Git.open(getRepositoryDir(originOwner, repository.name)),
|
||||
Git.open(getRepositoryDir(forkedOwner, repository.name))
|
||||
){ case (oldGit, newGit) =>
|
||||
val originBranch = JGitUtil.getDefaultBranch(oldGit, originRepository, tmpOriginBranch).get._2
|
||||
val forkedBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository, tmpForkedBranch).get._2
|
||||
|
||||
pulls.html.mergecheck(
|
||||
checkConflict(originOwner, repository.name, originBranch, forkedOwner, repository.name, forkedBranch))
|
||||
}
|
||||
}
|
||||
case _ => NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
post("/:owner/:repository/pulls/new", pullRequestForm)(referrersOnly { (form, repository) =>
|
||||
val loginUserName = context.loginAccount.get.userName
|
||||
|
||||
@@ -313,6 +305,40 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||
})
|
||||
|
||||
/**
|
||||
* Checks whether conflict will be caused in merging. Returns true if conflict will be caused.
|
||||
*/
|
||||
private def checkConflict(userName: String, repositoryName: String, branch: String,
|
||||
requestUserName: String, requestRepositoryName: String, requestBranch: String): Boolean = {
|
||||
// TODO Are there more quick way?
|
||||
LockUtil.lock(s"${userName}/${repositoryName}/merge-check"){
|
||||
val remote = getRepositoryDir(userName, repositoryName)
|
||||
val tmpdir = new java.io.File(getTemporaryDir(userName, repositoryName), "merge-check")
|
||||
if(tmpdir.exists()){
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
|
||||
val git = Git.cloneRepository.setDirectory(tmpdir).setURI(remote.toURI.toString).setBranch(branch).call
|
||||
try {
|
||||
git.checkout.setName(branch).call
|
||||
|
||||
git.fetch
|
||||
.setRemote(getRepositoryDir(requestUserName, requestRepositoryName).toURI.toString)
|
||||
.setRefSpecs(new RefSpec(s"refs/heads/${branch}:refs/heads/${requestBranch}")).call
|
||||
|
||||
val result = git.merge
|
||||
.include(git.getRepository.resolve("FETCH_HEAD"))
|
||||
.setCommit(false).call
|
||||
|
||||
result.getConflicts != null
|
||||
|
||||
} finally {
|
||||
git.getRepository.close
|
||||
FileUtils.deleteDirectory(tmpdir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses branch identifier and extracts owner and branch name as tuple.
|
||||
*
|
||||
@@ -382,7 +408,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
getPullRequestCountGroupByUser(condition.state == "closed", owner, Some(repoName)),
|
||||
userName,
|
||||
page,
|
||||
countIssue(condition.copy(state = "open"), filterUser, true, owner -> repoName),
|
||||
countIssue(condition.copy(state = "open" ), filterUser, true, owner -> repoName),
|
||||
countIssue(condition.copy(state = "closed"), filterUser, true, owner -> repoName),
|
||||
countIssue(condition, Map.empty, true, owner -> repoName),
|
||||
condition,
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
forkedId: String,
|
||||
sourceId: String,
|
||||
commitId: String,
|
||||
hasConflict: Boolean,
|
||||
repository: service.RepositoryService.RepositoryInfo,
|
||||
originRepository: service.RepositoryService.RepositoryInfo,
|
||||
forkedRepository: service.RepositoryService.RepositoryInfo,
|
||||
@@ -52,14 +51,9 @@
|
||||
<div class="box-content">
|
||||
<form method="POST" action="@path/@originRepository.owner/@repository.name/pulls/new" validate="true">
|
||||
<div style="width: 260px; position: absolute; margin-left: 635px;">
|
||||
@if(hasConflict){
|
||||
<h4>We can’t automatically merge these branches</h4>
|
||||
<p>Don't worry, you can still submit the pull request.</p>
|
||||
} else {
|
||||
<h4 style="color: #468847;">Able to merge</h4>
|
||||
<p>These branches can be automatically merged.</p>
|
||||
}
|
||||
<input type="submit" class="btn btn-success btn-block" value="Send pull request"/>
|
||||
<div class="check-conflict" style="display: none;">
|
||||
<img src="@assets/common/images/indicator.gif"/> Checking...
|
||||
</div>
|
||||
</div>
|
||||
<div style="width: 620px; border-right: 1px solid #d4d4d4;">
|
||||
<span class="error" id="error-title"></span>
|
||||
@@ -86,29 +80,6 @@
|
||||
</tr>
|
||||
</table>
|
||||
} else {
|
||||
@*
|
||||
<div class="box">
|
||||
<table class="table table-file-list" style="border: 1px solid silver;">
|
||||
@commits.map { day =>
|
||||
<tr>
|
||||
<th colspan="3" class="box-header" style="font-weight: normal;">@date(day.head.time)</th>
|
||||
</tr>
|
||||
@day.map { commit =>
|
||||
<tr>
|
||||
<td style="width: 20%;">
|
||||
@avatar(commit.committer, 20)
|
||||
<a href="@url(commit.committer)" class="username">@commit.committer</a>
|
||||
</td>
|
||||
<td>@commit.shortMessage</td>
|
||||
<td style="width: 10%; text-align: right;">
|
||||
<a href="@url(repository)/commit/@commit.id" class="monospace">@commit.id.substring(0, 7)</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</table>
|
||||
</div>
|
||||
*@
|
||||
@pulls.html.commits(commits, repository)
|
||||
@helper.html.diff(diffs, repository, Some(commitId), Some(sourceId), true)
|
||||
}
|
||||
@@ -148,5 +119,27 @@ $(function(){
|
||||
$(this).hide();
|
||||
$('#pull-request-form').show();
|
||||
});
|
||||
|
||||
@if(hasWritePermission){
|
||||
function checkConflict(from, to, noConflictHandler, hasConflictHandler){
|
||||
$('.check-conflict').show();
|
||||
$.get('@url(repository)/compare/' + from + '...' + to + '/mergecheck',
|
||||
function(data){ $('.check-conflict').html(data); });
|
||||
}
|
||||
|
||||
@if(members.isEmpty){
|
||||
checkConflict(
|
||||
$.trim($('i.icon-ok').parents('a.origin-branch').data('name')),
|
||||
$.trim($('i.icon-ok').parents('a.forked-branch').data('name'))
|
||||
);
|
||||
} else {
|
||||
checkConflict(
|
||||
$.trim($('i.icon-ok').parents('a.origin-owner' ).data('name')) + ":" +
|
||||
$.trim($('i.icon-ok').parents('a.origin-branch').data('name')),
|
||||
$.trim($('i.icon-ok').parents('a.forked-owner' ).data('name')) + ":" +
|
||||
$.trim($('i.icon-ok').parents('a.forked-branch').data('name'))
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
comments: List[model.IssueComment],
|
||||
collaborators: List[String],
|
||||
milestones: List[(model.Milestone, Int, Int)],
|
||||
hasConflict: Boolean,
|
||||
hasWritePermission: Boolean,
|
||||
repository: service.RepositoryService.RepositoryInfo,
|
||||
requestRepositoryUrl: String)(implicit context: app.Context)
|
||||
repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
<div class="row-fluid">
|
||||
@@ -17,71 +15,8 @@
|
||||
<div class="box issue-comment-box" style="background-color: #d8f5cd;">
|
||||
<div class="box-content"class="issue-content" style="border: 1px solid #95c97e; padding: 10px;">
|
||||
<div id="merge-pull-request">
|
||||
<div class="pull-right">
|
||||
<input type="button" class="btn btn-success" id="merge-pull-request-button" value="Merge pull request"@if(hasConflict){ disabled="true"}/>
|
||||
</div>
|
||||
<div>
|
||||
@if(hasConflict){
|
||||
<span class="strong">We can’t automatically merge this pull request.</span>
|
||||
} else {
|
||||
<span class="strong">This pull request can be automatically merged.</span>
|
||||
}
|
||||
</div>
|
||||
<div class="small">
|
||||
@if(hasConflict){
|
||||
<a href="#" id="show-command-line">Use the command line</a> to resolve conflicts before continuing.
|
||||
} else {
|
||||
You can also merge branches on the <a href="#" id="show-command-line">command line</a>.
|
||||
}
|
||||
</div>
|
||||
<div id="command-line" style="display: none;">
|
||||
<hr>
|
||||
@if(hasConflict){
|
||||
<span class="strong">Checkout via command line</span>
|
||||
<p>
|
||||
If you cannot merge a pull request automatically here, you have the option of checking
|
||||
it out via command line to resolve conflicts and perform a manual merge.
|
||||
</p>
|
||||
} else {
|
||||
<span class="strong">Merging via command line</span>
|
||||
<p>
|
||||
If you do not want to use the merge button or an automatic merge cannot be performed,
|
||||
you can perform a manual merge on the command line.
|
||||
</p>
|
||||
}
|
||||
@helper.html.copy("repository-url-copy", requestRepositoryUrl){
|
||||
<input type="text" value="@requestRepositoryUrl" id="repository-url" readonly>
|
||||
}
|
||||
<div>
|
||||
<p>
|
||||
<span class="strong">Step 1:</span> Check out a new branch to test the changes — run this from your project directory
|
||||
</p>
|
||||
@defining(s"git checkout -b ${pullreq.requestUserName}-${pullreq.requestBranch} ${pullreq.requestBranch}"){ command =>
|
||||
@helper.html.copy("merge-command-copy-1", command){
|
||||
<pre style="width: 500px; float: left;">@command</pre>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<span class="strong">Step 2:</span> Bring in @{pullreq.requestUserName}'s changes and test
|
||||
</p>
|
||||
@defining(s"git pull ${requestRepositoryUrl} ${pullreq.requestBranch}"){ command =>
|
||||
@helper.html.copy("merge-command-copy-2", command){
|
||||
<pre style="width: 500px; float: left;">@command</pre>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<span class="strong">Step 3:</span> Merge the changes and update the server
|
||||
</p>
|
||||
@defining(s"git checkout master\ngit merge ${pullreq.requestUserName}-${pullreq.branch}\ngit push origin ${pullreq.branch}"){ command =>
|
||||
@helper.html.copy("merge-command-copy-3", command){
|
||||
<pre style="width: 500px; float: left;">@command</pre>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div class="check-conflict" style="display: none;">
|
||||
<img src="@assets/common/images/indicator.gif"/> Checking...
|
||||
</div>
|
||||
</div>
|
||||
<div id="confirm-merge-form" style="display: none;">
|
||||
@@ -120,19 +55,15 @@
|
||||
</div>
|
||||
<script>
|
||||
$(function(){
|
||||
$('#show-command-line').click(function(){
|
||||
$('#command-line').show();
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#merge-pull-request-button').click(function(){
|
||||
$('#merge-pull-request').hide();
|
||||
$('#confirm-merge-form').show();
|
||||
});
|
||||
|
||||
$('#cancel-merge-pull-request').click(function(){
|
||||
$('#confirm-merge-form').hide();
|
||||
$('#merge-pull-request').show();
|
||||
});
|
||||
|
||||
@if(hasWritePermission){
|
||||
$('.check-conflict').show();
|
||||
$.get('@url(repository)/pull/@issue.issueId/mergeguide',
|
||||
function(data){ $('.check-conflict').html(data); });
|
||||
}
|
||||
});
|
||||
</script>
|
||||
9
src/main/twirl/pulls/mergecheck.scala.html
Normal file
9
src/main/twirl/pulls/mergecheck.scala.html
Normal file
@@ -0,0 +1,9 @@
|
||||
@(hasConflict: Boolean)
|
||||
@if(hasConflict){
|
||||
<h4>We can’t automatically merge these branches</h4>
|
||||
<p>Don't worry, you can still submit the pull request.</p>
|
||||
} else {
|
||||
<h4 style="color: #468847;">Able to merge</h4>
|
||||
<p>These branches can be automatically merged.</p>
|
||||
}
|
||||
<input type="submit" class="btn btn-success btn-block" value="Send pull request"/>
|
||||
84
src/main/twirl/pulls/mergeguide.scala.html
Normal file
84
src/main/twirl/pulls/mergeguide.scala.html
Normal file
@@ -0,0 +1,84 @@
|
||||
@(hasConflict: Boolean,
|
||||
pullreq: model.PullRequest,
|
||||
requestRepositoryUrl: String)(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
<div class="pull-right">
|
||||
<input type="button" class="btn btn-success" id="merge-pull-request-button" value="Merge pull request"@if(hasConflict){ disabled="true"}/>
|
||||
</div>
|
||||
<div>
|
||||
@if(hasConflict){
|
||||
<span class="strong">We can’t automatically merge this pull request.</span>
|
||||
} else {
|
||||
<span class="strong">This pull request can be automatically merged.</span>
|
||||
}
|
||||
</div>
|
||||
<div class="small">
|
||||
@if(hasConflict){
|
||||
<a href="#" id="show-command-line">Use the command line</a> to resolve conflicts before continuing.
|
||||
} else {
|
||||
You can also merge branches on the <a href="#" id="show-command-line">command line</a>.
|
||||
}
|
||||
</div>
|
||||
<div id="command-line" style="display: none;">
|
||||
<hr>
|
||||
@if(hasConflict){
|
||||
<span class="strong">Checkout via command line</span>
|
||||
<p>
|
||||
If you cannot merge a pull request automatically here, you have the option of checking
|
||||
it out via command line to resolve conflicts and perform a manual merge.
|
||||
</p>
|
||||
} else {
|
||||
<span class="strong">Merging via command line</span>
|
||||
<p>
|
||||
If you do not want to use the merge button or an automatic merge cannot be performed,
|
||||
you can perform a manual merge on the command line.
|
||||
</p>
|
||||
}
|
||||
@helper.html.copy("repository-url-copy", requestRepositoryUrl){
|
||||
<input type="text" value="@requestRepositoryUrl" id="repository-url" readonly>
|
||||
}
|
||||
<div>
|
||||
<p>
|
||||
<span class="strong">Step 1:</span> Check out a new branch to test the changes — run this from your project directory
|
||||
</p>
|
||||
@defining(s"git checkout -b ${pullreq.requestUserName}-${pullreq.requestBranch} ${pullreq.requestBranch}"){ command =>
|
||||
@helper.html.copy("merge-command-copy-1", command){
|
||||
<pre style="width: 500px; float: left;">@command</pre>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<span class="strong">Step 2:</span> Bring in @{pullreq.requestUserName}'s changes and test
|
||||
</p>
|
||||
@defining(s"git pull ${requestRepositoryUrl} ${pullreq.requestBranch}"){ command =>
|
||||
@helper.html.copy("merge-command-copy-2", command){
|
||||
<pre style="width: 500px; float: left;">@command</pre>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<span class="strong">Step 3:</span> Merge the changes and update the server
|
||||
</p>
|
||||
@defining(s"git checkout master\ngit merge ${pullreq.requestUserName}-${pullreq.branch}\ngit push origin ${pullreq.branch}"){ command =>
|
||||
@helper.html.copy("merge-command-copy-3", command){
|
||||
<pre style="width: 500px; float: left;">@command</pre>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function(){
|
||||
$('#show-command-line').click(function(){
|
||||
$('#command-line').show();
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#merge-pull-request-button').click(function(){
|
||||
$('#merge-pull-request').hide();
|
||||
$('#confirm-merge-form').show();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -5,10 +5,8 @@
|
||||
milestones: List[(model.Milestone, Int, Int)],
|
||||
dayByDayCommits: Seq[Seq[util.JGitUtil.CommitInfo]],
|
||||
diffs: Seq[util.JGitUtil.DiffInfo],
|
||||
hasConflict: Boolean,
|
||||
hasWritePermission: Boolean,
|
||||
repository: service.RepositoryService.RepositoryInfo,
|
||||
requestRepositoryUrl: String)(implicit context: app.Context)
|
||||
repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
@html.main("%s - Pull Request #%d - %s/%s".format(issue.title, issue.issueId, repository.owner, repository.name)){
|
||||
@@ -39,7 +37,7 @@
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="discussion">
|
||||
@pulls.html.discussion(issue, pullreq, comments, collaborators, milestones, hasConflict, hasWritePermission, repository, requestRepositoryUrl)
|
||||
@pulls.html.discussion(issue, pullreq, comments, collaborators, milestones, hasWritePermission, repository)
|
||||
</div>
|
||||
<div class="tab-pane" id="commits">
|
||||
@pulls.html.commits(dayByDayCommits, repository)
|
||||
|
||||
Reference in New Issue
Block a user