Skip to content

The Unified and Autonomous Development Platform

Add ability to squash commits in a pull request.

robin shine4907854db275
diff --git a/commons.git/src/main/java/com/pmease/commons/git/Git.java b/commons.git/src/main/java/com/pmease/commons/git/Git.java
index 0f12ac73bb..555f2b0661 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/Git.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/Git.java
@@ -377,6 +377,12 @@ public class Git implements Serializable {
.strategy(strategy).strategyOption(strategyOption).message(message).call();
}
+ public String squash(String revision, @Nullable String strategy, @Nullable String strategyOption,
+ @Nullable String message) {
+ return new MergeCommand(repoDir).revision(revision).squash(true)
+ .strategy(strategy).strategyOption(strategyOption).message(message).call();
+ }
+
public Git fetch(String from, String... refspec) {
new FetchCommand(repoDir).from(from).refspec(refspec).call();
return this;
diff --git a/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java b/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java
index c9352d768b..83b14135d5 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/command/MergeCommand.java
@@ -22,6 +22,8 @@ public class MergeCommand extends GitCommand<String> {
private FastForwardMode fastForwardMode;
+ private boolean squash;
+
private String strategy;
private String strategyOption;
@@ -51,6 +53,11 @@ public class MergeCommand extends GitCommand<String> {
this.strategyOption = strategyOption;
return this;
}
+
+ public MergeCommand squash(boolean squash) {
+ this.squash = squash;
+ return this;
+ }
public MergeCommand message(String message) {
this.message = message;
@@ -77,7 +84,9 @@ public class MergeCommand extends GitCommand<String> {
if (strategyOption != null)
cmd.addArgs("--strategy-option=" + strategyOption);
- if (message != null)
+ if (squash)
+ cmd.addArgs("--squash");
+ else if (message != null)
cmd.addArgs("-m", message);
cmd.addArgs(revision);
@@ -106,7 +115,10 @@ public class MergeCommand extends GitCommand<String> {
result.checkReturnCode();
- return new Git(repoDir).parseRevision("HEAD", true);
+ Git git = new Git(repoDir);
+ if (squash)
+ git.commit(message, false, false);
+ return git.parseRevision("HEAD", true);
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
index 337f705c33..ee3c9e09f0 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
@@ -5,8 +5,9 @@ import static com.pmease.gitplex.core.model.PullRequest.CriterionHelper.ofSource
import static com.pmease.gitplex.core.model.PullRequest.CriterionHelper.ofTarget;
import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;
-import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_SOURCE_BRANCH;
-import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_TARGET_BRANCH;
+import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
+import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
+import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
import java.io.File;
import java.util.Date;
@@ -145,24 +146,42 @@ public class DefaultPullRequestManager implements PullRequestManager {
if (preview == null)
throw new IllegalStateException("Integration preview has not been calculated yet.");
- String previewIntegrated = preview.getIntegrated();
- if (previewIntegrated == null)
+ String integrated = preview.getIntegrated();
+ if (integrated == null)
throw new IllegalStateException("There are integration conflicts.");
-
- if (request.getIntegrationStrategy() == REBASE_SOURCE_BRANCH) {
+
+ Git git = request.getTarget().getRepository().git();
+ IntegrationStrategy strategy = request.getIntegrationStrategy();
+ if ((strategy == MERGE_ALWAYS || strategy == MERGE_IF_NECESSARY || strategy == MERGE_WITH_SQUASH)
+ && !integrated.equals(preview.getRequestHead()) && comment != null) {
+ File tempDir = FileUtils.createTempDir();
+ try {
+ Git tempGit = new Git(tempDir);
+ tempGit.clone(git.repoDir().getAbsolutePath(), false, true, true, request.getTarget().getName());
+ tempGit.reset(null, null);
+
+ tempGit.updateRef("HEAD", integrated, null, null);
+ tempGit.commit(comment, false, true);
+ preview.setIntegrated(tempGit.parseRevision("HEAD", true));
+ git.fetch(tempGit, "+HEAD:" + request.getIntegrateRef());
+ } finally {
+ FileUtils.deleteDir(tempDir);
+ }
+ }
+ if (strategy == REBASE_SOURCE_ONTO_TARGET || strategy == MERGE_WITH_SQUASH) {
Git sourceGit = request.getSource().getRepository().git();
if (sourceGit.updateRef(request.getSource().getHeadRef(),
- previewIntegrated, preview.getRequestHead(),
- "Rebase for pull request: " + request.getId())) {
+ integrated, preview.getRequestHead(),
+ "Pull request #" + request.getId())) {
- request.getSource().setHeadCommitHash(previewIntegrated);
+ request.getSource().setHeadCommitHash(integrated);
request.getSource().setUpdater(user);
branchManager.save(request.getSource());
PullRequestUpdate update = new PullRequestUpdate();
update.setRequest(request);
update.setUser(user);
- update.setHeadCommitHash(previewIntegrated);
+ update.setHeadCommitHash(integrated);
request.getUpdates().add(update);
pullRequestUpdateManager.save(update);
@@ -171,10 +190,9 @@ public class DefaultPullRequestManager implements PullRequestManager {
"Unable to target branch '%s' due to lock failure.", request.getTarget()));
}
}
- Git git = request.getTarget().getRepository().git();
- if (git.updateRef(request.getTarget().getHeadRef(), previewIntegrated,
- preview.getTargetHead(), comment!=null?comment:"Pull request #" + request.getId())) {
- request.getTarget().setHeadCommitHash(previewIntegrated);
+ if (git.updateRef(request.getTarget().getHeadRef(), integrated,
+ preview.getTargetHead(), "Pull request #" + request.getId())) {
+ request.getTarget().setHeadCommitHash(integrated);
request.getTarget().setUpdater(user);
branchManager.save(request.getTarget());
@@ -319,7 +337,9 @@ public class DefaultPullRequestManager implements PullRequestManager {
request.getLatestUpdate().getHeadCommitHash(), request.getIntegrationStrategy(), null);
request.setIntegrationPreview(preview);
String integrateRef = request.getIntegrateRef();
- if (preview.getIntegrationStrategy() == MERGE_IF_NECESSARY && git.isAncestor(targetHead, requestHead)) {
+ if (preview.getIntegrationStrategy() == MERGE_IF_NECESSARY && git.isAncestor(targetHead, requestHead)
+ || preview.getIntegrationStrategy() == MERGE_WITH_SQUASH && git.isAncestor(targetHead, requestHead)
+ && git.log(targetHead, requestHead, null, 0, 0).size() == 1) {
preview.setIntegrated(requestHead);
git.updateRef(integrateRef, requestHead, null, null);
} else {
@@ -331,23 +351,30 @@ public class DefaultPullRequestManager implements PullRequestManager {
String integrated;
- if (preview.getIntegrationStrategy() == REBASE_TARGET_BRANCH) {
+ if (preview.getIntegrationStrategy() == REBASE_TARGET_ONTO_SOURCE) {
tempGit.updateRef("HEAD", requestHead, null, null);
tempGit.reset(null, null);
integrated = tempGit.cherryPick(".." + targetHead);
} else {
tempGit.updateRef("HEAD", targetHead, null, null);
tempGit.reset(null, null);
- if (preview.getIntegrationStrategy() == REBASE_SOURCE_BRANCH) {
+ if (preview.getIntegrationStrategy() == REBASE_SOURCE_ONTO_TARGET) {
integrated = tempGit.cherryPick(".." + requestHead);
+ } else if (preview.getIntegrationStrategy() == MERGE_WITH_SQUASH) {
+ String commitMessage = request.getTitle() + "\n\n";
+ if (request.getDescription() != null)
+ commitMessage += request.getDescription() + "\n\n";
+ commitMessage += "(squashed commit of pull request #" + request.getId() + ")\n";
+ integrated = tempGit.squash(requestHead, null, null, commitMessage);
} else {
FastForwardMode fastForwardMode;
if (preview.getIntegrationStrategy() == MERGE_ALWAYS)
fastForwardMode = FastForwardMode.NO_FF;
else
fastForwardMode = FastForwardMode.FF;
- integrated = tempGit.merge(requestHead, fastForwardMode, null, null,
- "Merge pull request: " + request.getTitle());
+ String commitMessage = "Merge pull request #" + request.getId()
+ + "\n\n" + request.getTitle() + "\n";
+ integrated = tempGit.merge(requestHead, fastForwardMode, null, null, commitMessage);
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
index b0cff47172..8e37a0ca8f 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
@@ -66,8 +66,8 @@ public class PullRequest extends AbstractEntity {
MERGE_ALWAYS("Merge always", "Always create merge commit when integrate into target branch"),
MERGE_IF_NECESSARY("Merge if necessary", "Create merge commit only if target branch can not be fast-forwarded to the pull request"),
MERGE_WITH_SQUASH("Merge with squash", "Squash all commits in the pull request and then merge with target branch"),
- REBASE_SOURCE_BRANCH("Rebase source branch", "Rebase source branch on top of target branch and then fast-forward target branch to source branch"),
- REBASE_TARGET_BRANCH("Rebase target branch", "Rebase target branch on top of source branch");
+ REBASE_SOURCE_ONTO_TARGET("Rebase source onto target", "Rebase source branch onto target branch and then fast-forward target branch to source branch"),
+ REBASE_TARGET_ONTO_SOURCE("Rebase target onto source", "Rebase target branch onto source branch");
private final String displayName;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
index 417ef0fd9c..8def10daf1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
@@ -856,30 +856,31 @@ ul.status-help li:last-child .description {border-bottom: none;}
/* PULL REQUEST DETAIL PANEL */
.request-detail {padding: 20px;}
.request-detail>div {margin-bottom: 20px;}
+.request-detail>div.title {margin-bottom: 10px;}
.request-detail>div:last-child {margin-bottom: 0;}
.request-detail table {width: 100%;}
.request-detail td {vertical-align: top;}
.request-detail .verification-status {cursor: pointer;}
-.request-detail>.overview {margin-bottom: 20px;}
-.request-detail>.overview>div {margin-bottom: 20px;}
-.request-detail>.overview>div:last-child {margin-bottom: 0;}
-.request-detail>.overview>.title {font-size: 24px; font-weight: bold; padding: 0;}
-.request-detail>.overview>.title input[type="text"] {width: 600px;}
-.request-detail>.overview>.title a i {color: #999; font-size: 19px;}
-.request-detail>.overview>.title>div {margin-right: 8px;}
-.request-detail>.overview>.title {margin-bottom: 12px;}
-.request-detail>.overview>.title>.id {color: #999;}
-
-.request-detail>.overview>.status {font-size: 18px;}
-
-.request-detail>.overview>.integration .preview>div:FIRST-CHILD:BEFORE {font-family: "ponticons";
- margin-right: 4px; font-size: 16px;}
-.request-detail>.overview>.integration .preview.alert-success>div:FIRST-CHILD:BEFORE {content: "\f250";}
-.request-detail>.overview>.integration .preview.alert-warning>div:FIRST-CHILD:BEFORE {content: "\f260";}
-
-.request-detail>.overview>.operations a {margin-right: 8px;}
-.request-detail>.overview>.operations .confirm {margin-top: 12px;}
+.request-detail>.title {font-size: 24px; font-weight: bold; padding: 0;}
+.request-detail>.title input[type="text"] {width: 600px;}
+.request-detail>.title a i {color: #999; font-size: 19px;}
+.request-detail>.title>div {margin-right: 8px;}
+.request-detail>.title>.id {color: #999;}
+
+.request-detail>.overview>.panel-body>div {padding: 12px 0; border-bottom: 1px dotted #BBB;}
+.request-detail>.overview>.panel-body>div:last-child {padding: 8px 0 0 0; border-bottom: none;}
+.request-detail>.overview>.panel-body>div:first-child {padding: 0 0 8px 0;}
+.request-detail>.overview>.panel-body>div:first-child:last-child {padding: 0; border-bottom: none;}
+
+.request-detail>.overview>.panel-body>.status>.reasons>.reason .fa {font-size: 10px; vertical-align: middle;}
+.request-detail>.overview>.panel-body>.integration>.preview>div {padding: 8px; margin: 8px 0 0 0;
+ border: none; box-shadow: none;}
+.request-detail>.overview>.panel-body>.integration>.preview>.well img {width: 20px; height: 20px;}
+
+.request-detail>.overview>.panel-body>.operations>.buttons>a,
+.request-detail>.overview>.panel-body>.operations>.confirm>form>input {margin-right: 8px;}
+.request-detail>.overview>.panel-body>.operations>.confirm>form>div>textarea {margin-bottom: 12px;}
.request-detail>.activities {margin-bottom: 20px; border-bottom: 1px solid #DDD;}
.request-detail>.activities>tbody>tr.discussion>td {border-top: 1px solid #DDD; padding: 12px 0;}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.html
index a20b071786..78bf500334 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.html
@@ -1,29 +1,29 @@
<wicket:extend>
<div class="request-detail">
- <div class="overview">
- <div wicket:id="requestTitle" class="title clearfix">
- <div wicket:id="title" class="title pull-left"></div>
- <div wicket:id="id" class="id pull-left"></div>
- <a wicket:id="editLink" title="Edit title" class="edit"><i class="fa fa-pencil"></i></a>
- <form wicket:id="editForm" class="pull-left form-inline">
- <input wicket:id="title" type="text" placeholder="Input title" class="form-control input-sm"></input>
- <input wicket:id="save" type="submit" value="Save" class="btn btn-sm btn-primary"/>
- <input wicket:id="cancel" type="button" value="Cancel" class="btn btn-sm btn-default"/>
- </form>
- </div>
- <div class="origin">
- <span wicket:id="requestSubmitter"></span>
- wants to pull into
- <span wicket:id="targetBranch"></span>
- <wicket:enclosure child="sourceBranch">
- from
- <span wicket:id="sourceBranch"></span>
- </wicket:enclosure>
- <span wicket:id="requestDate"></span>
- </div>
- <div wicket:id="requestStatus" class="status">
- <div wicket:id="summary" class="summary"></div>
- <div class="detail">
+ <div wicket:id="requestTitle" class="title clearfix">
+ <div wicket:id="title" class="title pull-left"></div>
+ <div wicket:id="id" class="id pull-left"></div>
+ <a wicket:id="editLink" title="Edit title" class="edit"><i class="fa fa-pencil"></i></a>
+ <form wicket:id="editForm" class="pull-left form-inline">
+ <input wicket:id="title" type="text" placeholder="Input title" class="form-control input-sm"></input>
+ <input wicket:id="save" type="submit" value="Save" class="btn btn-sm btn-primary"/>
+ <input wicket:id="cancel" type="button" value="Cancel" class="btn btn-sm btn-default"/>
+ </form>
+ </div>
+ <div class="originate">
+ <span wicket:id="requestSubmitter"></span>
+ wants to pull into
+ <span wicket:id="targetBranch"></span>
+ <wicket:enclosure child="sourceBranch">
+ from
+ <span wicket:id="sourceBranch"></span>
+ </wicket:enclosure>
+ <span wicket:id="requestDate"></span>
+ </div>
+ <div wicket:id="requestOverview" class="overview panel">
+ <div class="panel-heading"><span wicket:id="title" class="panel-title"></span></div>
+ <div class="panel-body">
+ <div wicket:id="status" class="status">
<div wicket:id="fastForwarded">
Target branch was fast forwarded to this request.
</div>
@@ -33,78 +33,90 @@
<div wicket:id="mergedOutside">
Head commit of this request was merged into target branch outside of this pull request.
</div>
+ <div wicket:id="squashed">
+ <p>Per the integration strategy, commits in this pull request from source branch <span wicket:id="source"></span>
+ was squashed before merging into target branch <span wicket:id="target"></span>.</p>
+ <p>If you have a local branch whose upstream tracking branch
+ points to source branch, please run this command to do the sync:
+ <kbd>git fetch origin && git rebase</kbd>
+ </p>
+ </div>
<div wicket:id="sourceRebased">
- <p>Source branch <span wicket:id="source"></span> was rebased on top
+ <p>Per the integration strategy, source branch <span wicket:id="source"></span> was rebased on top
of target branch <span wicket:id="target"></span>, and then target
- branch was fast forwarded to rebased result per the integration
- strategy.</p>
+ branch was fast forwarded to rebased result.</p>
<p>If you have a local branch whose upstream tracking branch
points to source branch, please run this command to do the sync:
<kbd>git fetch origin && git rebase</kbd>
</p>
</div>
<div wicket:id="targetRebased">
- <p>Target branch <span wicket:id="target"></span> was rebased on top of
- this request per the integration strategy.</p>
+ <p>Per the integration strategy, target branch <span wicket:id="target"></span> was rebased on top of this request.</p>
<p>If you have a local branch whose upstream tracking
branch points to target branch, please run this command to do the sync:
<kbd>git fetch origin && git rebase</kbd>
</p>
</div>
- <div wicket:id="discarded"></div>
<wicket:enclosure child="reasons">
<div class="reasons">
- <div wicket:id="reasons" class="reason"><span wicket:id="reason"></span></div>
+ <div wicket:id="reasons" class="reason"><i class="fa fa-primitive-square"></i> <span wicket:id="reason"></span></div>
</div>
</wicket:enclosure>
</div>
- </div>
- <div wicket:id="requestIntegration" class="integration">
- <div class="strategy clearfix">
- <div class="pull-left">Integration Strategy:</div>
- <div class="pull-left"><select wicket:id="strategySelect" class="form-control input-sm"></select></div>
- <div wicket:id="strategyLabel" class="pull-left"></div>
- <div wicket:id="strategyHelp" class="pull-left fa fa-question-circle pointer"></div>
- </div>
- <div class="preview">
- <div wicket:id="calculating" class="well">
- <img src="/assets/img/ajax-loader.gif"></img> Calculating integration preview...
+ <div wicket:id="integration" class="integration">
+ <div class="strategy">
+ <i class="fa fa-chevron-right"></i>
+ Integration Strategy:
+ <select wicket:id="strategySelect"></select>
+ <span wicket:id="strategyLabel"></span>
+ <span wicket:id="strategyHelp" class="fa fa-question-circle pointer"></span>
</div>
- <div wicket:id="noConflict" class="alert alert-success">
- <span>Able to integrate without conflicts.</span>
- <wicket:enclosure child="preview">
- <span class="fa fa-arrow-right"></span> <a wicket:id="preview">Preview</a> the integration result.
- </wicket:enclosure>
- <wicket:enclosure child="verification">
- <span class="fa fa-arrow-right"></span> Build of the integration is <span wicket:id="verification"></span>
- </wicket:enclosure>
- </div>
- <div wicket:id="conflict" class="alert alert-warning">
- <span>There are integration conflicts.</span>
- <wicket:enclosure child="resolveInstructionsTrigger">
- Please follow <a wicket:id="resolveInstructionsTrigger" href="javascript:void(0);">this instruction</a> to resolve the conflicts.
- <div wicket:id="resolveInstructions"></div>
- </wicket:enclosure>
+ <div class="preview">
+ <div wicket:id="calculating" class="well">
+ <img src="/assets/img/ajax-loader.gif"></img> Calculating integration preview...
+ </div>
+ <div wicket:id="noConflict" class="alert alert-success">
+ <span><i class="fa fa-tick-round"></i> Able to integrate without conflicts.</span>
+ <wicket:enclosure child="preview">
+ <span class="fa fa-arrow-right"></span> <a wicket:id="preview">Preview</a> the integration result.
+ </wicket:enclosure>
+ <wicket:enclosure child="verification">
+ <span class="fa fa-arrow-right"></span> Build of the integration is <span wicket:id="verification"></span>
+ </wicket:enclosure>
+ </div>
+ <div wicket:id="conflict" class="alert alert-warning">
+ <span><i class="fa fa-alert-o"></i> There are integration conflicts.</span>
+ <wicket:enclosure child="resolveInstructionsTrigger">
+ Please follow <a wicket:id="resolveInstructionsTrigger" href="javascript:void(0);">this instruction</a> to resolve the conflicts.
+ <div wicket:id="resolveInstructions"></div>
+ </wicket:enclosure>
+ </div>
</div>
</div>
- </div>
- <div wicket:id="requestOperations" class="operations">
- <div class="buttons">
- <a wicket:id="approve" class="btn btn-primary" href="javascript:void(0);">Approve</a>
- <a wicket:id="disapprove" class="btn btn-primary" href="javascript:void(0);">Disapprove</a>
- <a wicket:id="integrate" class="btn btn-success">Integrate</a>
- <a wicket:id="discard" class="btn btn-danger">Discard</a>
+ <div wicket:id="operations" class="operations">
+ <div class="buttons">
+ <a wicket:id="approve" class="btn btn-primary" href="javascript:void(0);">Approve</a>
+ <a wicket:id="disapprove" class="btn btn-primary" href="javascript:void(0);">Disapprove</a>
+ <a wicket:id="integrate" class="btn btn-success">Integrate</a>
+ <a wicket:id="discard" class="btn btn-danger">Discard</a>
+ </div>
+ <div wicket:id="confirm" class="confirm"></div>
</div>
- <form wicket:id="confirm" class="confirm">
- <div wicket:id="comment"></div>
- <div wicket:id="feedback"></div>
- <input wicket:id="submit" type="submit" value="Confirm" class="btn"></input>
- <input wicket:id="cancel" type="button" value="Cancel" class="btn btn-default"></input>
- </form>
</div>
</div>
<div wicket:id="requestTabs" class="tabs"></div>
<wicket:child></wicket:child>
<div wicket:id="backToTop"></div>
</div>
+ <wicket:fragment wicket:id="commitMessageFrag">
+ <textarea wicket:id="commitMessage" class="form-control" placeholder="Commit message"></textarea>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="operationConfirmFrag">
+ <form wicket:id="form">
+ <div wicket:id="note"></div>
+ <div wicket:id="feedback"></div>
+ <input wicket:id="submit" type="submit" value="Confirm" class="btn"></input>
+ <input wicket:id="cancel" type="button" value="Cancel" class="btn btn-default"></input>
+ </form>
+ </wicket:fragment>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
index efc6c3730d..ee1fe96359 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
@@ -2,8 +2,9 @@ package com.pmease.gitplex.web.page.repository.pullrequest;
import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;
-import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_SOURCE_BRANCH;
-import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_TARGET_BRANCH;
+import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
+import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
+import static com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
import static com.pmease.gitplex.core.model.PullRequest.Status.DISCARDED;
import static com.pmease.gitplex.core.model.PullRequest.Status.INTEGRATED;
import static com.pmease.gitplex.core.model.PullRequest.Status.PENDING_INTEGRATE;
@@ -24,6 +25,7 @@ import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseException;
+import org.apache.wicket.Session;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
@@ -35,11 +37,13 @@ import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
+import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
@@ -87,7 +91,7 @@ public abstract class RequestDetailPage extends RepositoryPage {
private boolean editingTitle;
- private PullRequestOperation operationToConfirm;
+ private WebMarkupContainer overviewContainer;
public RequestDetailPage(final PageParameters params) {
super(params);
@@ -244,9 +248,44 @@ public abstract class RequestDetailPage extends RepositoryPage {
}));
- add(newStatusContainer());
- add(newIntegrationContainer());
- add(newOperationsContainer());
+ overviewContainer = new WebMarkupContainer("requestOverview");
+ overviewContainer.setOutputMarkupId(true);
+
+ add(overviewContainer);
+ overviewContainer.add(new Label("title", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ if (getPullRequest().getStatus() == DISCARDED)
+ return "This request is discarded";
+ else if (getPullRequest().getStatus() == INTEGRATED)
+ return "This request is integrated";
+ else if (getPullRequest().getStatus() == PENDING_INTEGRATE)
+ return "This request is pending integrate";
+ else if (getPullRequest().getStatus() == PENDING_UPDATE)
+ return "This request is pending update";
+ else
+ return "This request is pending approval";
+ }
+
+ }));
+ overviewContainer.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ if (getPullRequest().getStatus() == INTEGRATED)
+ return "panel-success";
+ else if (getPullRequest().getStatus() == DISCARDED)
+ return "panel-danger";
+ else
+ return "panel-default";
+ }
+
+ }));
+ overviewContainer.setOutputMarkupId(true);
+ overviewContainer.add(newStatusContainer());
+ overviewContainer.add(newIntegrationContainer());
+ overviewContainer.add(newOperationsContainer());
List<Tab> tabs = new ArrayList<>();
@@ -267,21 +306,41 @@ public abstract class RequestDetailPage extends RepositoryPage {
}
private WebMarkupContainer newOperationsContainer() {
- final WebMarkupContainer operationsContainer = new WebMarkupContainer("requestOperations");
- operationsContainer.setOutputMarkupId(true);
+ final WebMarkupContainer operationsContainer = new WebMarkupContainer("operations") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ boolean hasVisibleChildren = false;
+ for (int i=0; i<size(); i++) {
+ Component child = get(i);
+ child.configure();
+ if (child.isVisible()) {
+ hasVisibleChildren = true;
+ break;
+ }
+ }
+
+ setVisible(hasVisibleChildren);
+ }
+
+ };
+
+ final String confirmId = "confirm";
operationsContainer.add(new AjaxLink<Void>("approve") {
@Override
public void onClick(AjaxRequestTarget target) {
- operationToConfirm = APPROVE;
- target.add(operationsContainer);
+ operationsContainer.replace(newOperationConfirm(confirmId, APPROVE));
+ target.add(overviewContainer);
}
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(APPROVE.canOperate(getPullRequest()) && operationToConfirm == null);
+ setVisible(APPROVE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
}
});
@@ -290,15 +349,14 @@ public abstract class RequestDetailPage extends RepositoryPage {
@Override
public void onClick(AjaxRequestTarget target) {
- operationToConfirm = DISAPPROVE;
- target.add(operationsContainer);
+ operationsContainer.replace(newOperationConfirm(confirmId, DISAPPROVE));
+ target.add(overviewContainer);
}
@Override
protected void onConfigure() {
super.onConfigure();
-
- setVisible(DISAPPROVE.canOperate(getPullRequest()) && operationToConfirm == null);
+ setVisible(DISAPPROVE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
}
});
@@ -307,15 +365,14 @@ public abstract class RequestDetailPage extends RepositoryPage {
@Override
public void onClick(AjaxRequestTarget target) {
- operationToConfirm = INTEGRATE;
- target.add(operationsContainer);
+ operationsContainer.replace(newOperationConfirm(confirmId, INTEGRATE));
+ target.add(overviewContainer);
}
@Override
protected void onConfigure() {
super.onConfigure();
-
- setVisible(INTEGRATE.canOperate(getPullRequest()) && operationToConfirm == null);
+ setVisible(INTEGRATE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
}
});
@@ -324,51 +381,63 @@ public abstract class RequestDetailPage extends RepositoryPage {
@Override
public void onClick(AjaxRequestTarget target) {
- operationToConfirm = DISCARD;
- target.add(operationsContainer);
+ operationsContainer.replace(newOperationConfirm(confirmId, DISCARD));
+ target.add(overviewContainer);
}
@Override
protected void onConfigure() {
super.onConfigure();
-
- setVisible(DISCARD.canOperate(getPullRequest()) && operationToConfirm == null);
+ setVisible(DISCARD.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
}
});
+ operationsContainer.add(new WebMarkupContainer(confirmId).setVisible(false));
- Form<?> confirmForm = new Form<Void>("confirm") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(operationToConfirm != null);
+ return operationsContainer;
+ }
+
+ private Component newOperationConfirm(final String id, final PullRequestOperation operation) {
+ final Fragment fragment = new Fragment(id, "operationConfirmFrag", this);
+ Form<?> form = new Form<Void>("form");
+ fragment.add(form);
+ final FormComponent<String> noteInput;
+ if (operation != INTEGRATE) {
+ form.add(noteInput = new MarkdownInput("note", Model.of("")));
+ } else {
+ PullRequestManager manager = GitPlex.getInstance(PullRequestManager.class);
+ IntegrationPreview preview = manager.previewIntegration(getPullRequest());
+ if (preview == null || preview.getIntegrated() == null) {
+ Session.get().warn("Unable to integrate now as integration preview has to be recalculated");
+ return new WebMarkupContainer(id).setVisible(false);
+ }
+ IntegrationStrategy strategy = preview.getIntegrationStrategy();
+ if (strategy == REBASE_SOURCE_ONTO_TARGET
+ || strategy == REBASE_TARGET_ONTO_SOURCE
+ || preview.getIntegrated().equals(preview.getRequestHead())) {
+ form.add(noteInput = new MarkdownInput("note", Model.of("")));
+ } else {
+ Fragment noteFragment = new Fragment("note", "commitMessageFrag", this);
+ noteFragment.add(noteInput = new TextArea<String>("commitMessage", Model.of("")));
+ form.add(noteFragment);
}
-
- };
- operationsContainer.add(confirmForm);
-
- final FormComponent<String> commentInput = new MarkdownInput("comment", Model.of(""));
- confirmForm.add(commentInput);
- confirmForm.add(new FeedbackPanel("feedback", confirmForm));
- confirmForm.add(new AjaxButton("submit") {
+ }
+ form.add(new FeedbackPanel("feedback", form));
+ form.add(new AjaxButton("submit") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
super.onSubmit(target, form);
- String actionName = operationToConfirm.name().toLowerCase();
+ String actionName = operation.name().toLowerCase();
PullRequest request = getPullRequest();
try {
- operationToConfirm.operate(request, commentInput.getModelObject());
- operationToConfirm = null;
- commentInput.setModelObject(null);
-
+ operation.operate(request, noteInput.getModelObject());
setResponsePage(getPage().getClass(), paramsOf(getPullRequest()));
} catch (Exception e) {
error("Unable to " + actionName + ": " + e.getMessage());
- target.add(operationsContainer);
+ target.add(overviewContainer);
}
}
@@ -376,40 +445,39 @@ public abstract class RequestDetailPage extends RepositoryPage {
@Override
public String getObject() {
- return "Confirm " + WordUtils.capitalizeFully(operationToConfirm.name());
+ return "Confirm " + WordUtils.capitalizeFully(operation.name());
}
})).add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
- if (operationToConfirm == APPROVE)
+ if (operation == APPROVE)
return "btn-primary";
- else if (operationToConfirm == DISAPPROVE)
+ else if (operation == DISAPPROVE)
return "btn-primary";
- else if (operationToConfirm == INTEGRATE)
+ else if (operation == INTEGRATE)
return "btn-success";
else
return "btn-danger";
}
})));
- confirmForm.add(new AjaxLink<Void>("cancel") {
+ form.add(new AjaxLink<Void>("cancel") {
@Override
public void onClick(AjaxRequestTarget target) {
- operationToConfirm = null;
- commentInput.setModelObject(null);
- target.add(operationsContainer);
+ fragment.replaceWith(new WebMarkupContainer(id).setVisible(false));
+ target.add(overviewContainer);
}
});
- return operationsContainer;
+ return fragment;
}
private WebMarkupContainer newIntegrationContainer() {
- final WebMarkupContainer integrationContainer = new WebMarkupContainer("requestIntegration") {
+ WebMarkupContainer integrationContainer = new WebMarkupContainer("integration") {
@Override
protected void onConfigure() {
@@ -418,7 +486,6 @@ public abstract class RequestDetailPage extends RepositoryPage {
}
};
- integrationContainer.setOutputMarkupId(true);
PullRequest request = getPullRequest();
@@ -459,7 +526,7 @@ public abstract class RequestDetailPage extends RepositoryPage {
@Override
protected void onUpdate(AjaxRequestTarget target) {
GitPlex.getInstance(Dao.class).persist(getPullRequest());
- target.add(integrationContainer);
+ target.add(overviewContainer);
}
});
@@ -646,38 +713,26 @@ public abstract class RequestDetailPage extends RepositoryPage {
}
private WebMarkupContainer newStatusContainer() {
- WebMarkupContainer statusContainer = new WebMarkupContainer("requestStatus");
- statusContainer.setOutputMarkupId(true);
- statusContainer.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
+ WebMarkupContainer statusContainer = new WebMarkupContainer("status") {
@Override
- public String getObject() {
- if (getPullRequest().getStatus() == DISCARDED)
- return " alert alert-danger";
- else if (getPullRequest().getStatus() == INTEGRATED)
- return " alert alert-success";
- else
- return " well";
- }
-
- }));
- statusContainer.add(new Label("summary", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- if (getPullRequest().getStatus() == DISCARDED)
- return "This request is discarded";
- else if (getPullRequest().getStatus() == INTEGRATED)
- return "This request is integrated";
- else if (getPullRequest().getStatus() == PENDING_INTEGRATE)
- return "This request is pending integrate";
- else if (getPullRequest().getStatus() == PENDING_UPDATE)
- return "This request is pending update";
- else
- return "This request is pending approval";
+ protected void onConfigure() {
+ super.onConfigure();
+
+ boolean hasVisibleChildren = false;
+ for (int i=0; i<size(); i++) {
+ Component child = get(i);
+ child.configure();
+ if (child.isVisible()) {
+ hasVisibleChildren = true;
+ break;
+ }
+ }
+
+ setVisible(hasVisibleChildren);
}
- }));
+ };
statusContainer.add(new WebMarkupContainer("fastForwarded") {
@Override
@@ -717,7 +772,7 @@ public abstract class RequestDetailPage extends RepositoryPage {
}
});
- WebMarkupContainer sourceRebasedContainer = new WebMarkupContainer("sourceRebased") {
+ WebMarkupContainer squashedContainer = new WebMarkupContainer("squashed") {
@Override
protected void onConfigure() {
@@ -727,13 +782,13 @@ public abstract class RequestDetailPage extends RepositoryPage {
IntegrationPreview preview = request.getIntegrationPreview();
setVisible(request.getStatus() == INTEGRATED && preview != null
&& !preview.getRequestHead().equals(preview.getIntegrated())
- && preview.getIntegrationStrategy() == REBASE_SOURCE_BRANCH);
+ && preview.getIntegrationStrategy() == MERGE_WITH_SQUASH);
}
};
- statusContainer.add(sourceRebasedContainer);
- sourceRebasedContainer.add(new BranchLink("target", new EntityModel<Branch>(getPullRequest().getTarget())));
- sourceRebasedContainer.add(new BranchLink("source", new AbstractReadOnlyModel<Branch>() {
+ statusContainer.add(squashedContainer);
+ squashedContainer.add(new BranchLink("target", new EntityModel<Branch>(getPullRequest().getTarget())));
+ squashedContainer.add(new BranchLink("source", new AbstractReadOnlyModel<Branch>() {
@Override
public Branch getObject() {
@@ -750,7 +805,7 @@ public abstract class RequestDetailPage extends RepositoryPage {
});
- WebMarkupContainer targetRebasedContainer = new WebMarkupContainer("targetRebased") {
+ WebMarkupContainer sourceRebasedContainer = new WebMarkupContainer("sourceRebased") {
@Override
protected void onConfigure() {
@@ -760,23 +815,45 @@ public abstract class RequestDetailPage extends RepositoryPage {
IntegrationPreview preview = request.getIntegrationPreview();
setVisible(request.getStatus() == INTEGRATED && preview != null
&& !preview.getRequestHead().equals(preview.getIntegrated())
- && preview.getIntegrationStrategy() == REBASE_TARGET_BRANCH);
+ && preview.getIntegrationStrategy() == REBASE_SOURCE_ONTO_TARGET);
}
};
- statusContainer.add(targetRebasedContainer);
- targetRebasedContainer.add(new BranchLink("target", new EntityModel<Branch>(getPullRequest().getTarget())));
+ statusContainer.add(sourceRebasedContainer);
+ sourceRebasedContainer.add(new BranchLink("target", new EntityModel<Branch>(getPullRequest().getTarget())));
+ sourceRebasedContainer.add(new BranchLink("source", new AbstractReadOnlyModel<Branch>() {
+
+ @Override
+ public Branch getObject() {
+ return getPullRequest().getSource();
+ }
+
+ }) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getSource() != null);
+ }
+
+ });
- statusContainer.add(new WebMarkupContainer("discarded") {
+ WebMarkupContainer targetRebasedContainer = new WebMarkupContainer("targetRebased") {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getStatus() == DISCARDED);
+ PullRequest request = getPullRequest();
+ IntegrationPreview preview = request.getIntegrationPreview();
+ setVisible(request.getStatus() == INTEGRATED && preview != null
+ && !preview.getRequestHead().equals(preview.getIntegrated())
+ && preview.getIntegrationStrategy() == REBASE_TARGET_ONTO_SOURCE);
}
- });
+ };
+ statusContainer.add(targetRebasedContainer);
+ targetRebasedContainer.add(new BranchLink("target", new EntityModel<Branch>(getPullRequest().getTarget())));
statusContainer.add(new ListView<String>("reasons", new AbstractReadOnlyModel<List<String>>() {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.html
index fc6dab7ab5..f812386384 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.html
@@ -88,4 +88,27 @@
</div>
</div>
</wicket:fragment>
+
+ <wicket:fragment wicket:id="squashFrag">
+ <div class="conflict-resolve-instruction">
+ <p>From working directory of repository <em wicket:id="destRepoName"></em>,
+ check out target branch and merge with source branch with squash option.</p>
+ <div class="terminal">
+ <div>git checkout <span wicket:id="destBranchNameForCheckout"></span></div>
+ <div wicket:id="sameRepo">
+ <div>git fetch origin</div>
+ <div>git merge --squash origin/<span wicket:id="srcBranchName"></span></div>
+ </div>
+ <div wicket:id="differentRepo">
+ <div>git pull --squash <span wicket:id="srcRepoUrl"></span> <span wicket:id="srcBranchName"></span></div>
+ </div>
+ </div>
+ <p>
+ <p>Step 2: Resolve merge conflicts, commit merge result, test changes and force push result commit to GitPlex.</p>
+ <div class="terminal">
+ git commit
+ git push -f origin <span wicket:id="destBranchNameForPush"></span>
+ </div>
+ </div>
+ </wicket:fragment>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.java
index 7a38ada420..dc3a3e6e16 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/ResolveConflictInstructionPanel.java
@@ -38,7 +38,22 @@ class ResolveConflictInstructionPanel extends Panel {
String sourceHead = preview.getRequestHead();
IntegrationStrategy strategy = request.getIntegrationStrategy();
boolean sameRepo = request.getTarget().getRepository().equals(request.getSource().getRepository());
- if (strategy == REBASE_SOURCE_BRANCH) {
+ if (strategy == MERGE_WITH_SQUASH) {
+ fragment = new Fragment("content", "squashFrag", this);
+ fragment.add(new Label("destRepoName", request.getTarget().getRepository()));
+ fragment.add(new Label("destBranchNameForCheckout", request.getTarget().getName()));
+ fragment.add(new Label("destBranchNameForPush", request.getTarget().getName()));
+ WebMarkupContainer sameRepoContainer = new WebMarkupContainer("sameRepo");
+ sameRepoContainer.add(new Label("srcBranchName", request.getSource().getName()));
+ sameRepoContainer.setVisible(sameRepo);
+ fragment.add(sameRepoContainer);
+ WebMarkupContainer differentRepoContainer = new WebMarkupContainer("differentRepo");
+ differentRepoContainer.add(new Label("srcRepoUrl", request.getSource().getRepository().getUrl()));
+ differentRepoContainer.add(new Label("srcBranchName", request.getSource().getName()));
+ differentRepoContainer.setVisible(!sameRepo);
+ fragment.add(differentRepoContainer);
+ }
+ if (strategy == REBASE_SOURCE_ONTO_TARGET) {
fragment = new Fragment("content", "rebaseInSourceFrag", this);
fragment.add(new Label("srcRepoName", request.getSource().getRepository()));
fragment.add(new Label("srcBranchNameForCheckout", request.getSource().getName()));
@@ -52,7 +67,7 @@ class ResolveConflictInstructionPanel extends Panel {
differentRepoContainer.add(new Label("destBranchName", request.getTarget().getName()));
differentRepoContainer.setVisible(!sameRepo);
fragment.add(differentRepoContainer);
- } else if (strategy == REBASE_TARGET_BRANCH) {
+ } else if (strategy == REBASE_TARGET_ONTO_SOURCE) {
fragment = new Fragment("content", "rebaseInTargetFrag", this);
fragment.add(new Label("destRepoName", request.getTarget().getRepository()));
fragment.add(new Label("destBranchNameForCheckout", request.getTarget().getName()));