summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker <robin@nibor.org>2011-04-06 22:55:10 +0200
committerRobin Stocker <robin@nibor.org>2011-04-06 22:57:49 +0200
commit5dbef3fa51053b37f68b44ed390cab6dc8336dcc (patch)
tree3c45c0394a561fc091c1ad0c2239f10ef9d8b1e0
parent3151657404859454bdf60345c09b536d1269c0c8 (diff)
downloadjgit-5dbef3fa51053b37f68b44ed390cab6dc8336dcc.tar.gz
jgit-5dbef3fa51053b37f68b44ed390cab6dc8336dcc.zip
Add "Conflicts" section to merge message on conflict
The same as with cherry-pick, the commit message of a merge should include a "Conflicts" section when the merge resulted in conflicts. Change-Id: I6261dc898262322924af5ca1bef841a654b0df55 Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java32
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java14
2 files changed, 43 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
index 94f0906a30..d5c00257bb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
@@ -54,6 +54,7 @@ import java.util.Iterator;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.merge.MergeStrategy;
@@ -205,6 +206,37 @@ public class MergeCommandTest extends RepositoryTestCase {
}
@Test
+ public void testMergeMessage() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "1\na\n3\n");
+ git.add().addFilepattern("a").call();
+ RevCommit initialCommit = git.commit().setMessage("initial").call();
+
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+
+ writeTrashFile("a", "1\na(side)\n3\n");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("side").call();
+
+ checkoutBranch("refs/heads/master");
+
+ writeTrashFile("a", "1\na(main)\n3\n");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("main").call();
+
+ Ref sideBranch = db.getRef("side");
+
+ git.merge().include(sideBranch)
+ .setStrategy(MergeStrategy.RESOLVE).call();
+
+ assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n",
+ db.readMergeCommitMsg());
+
+ }
+
+ @Test
public void testMergeNonVersionedPaths() throws Exception {
Git git = new Git(db);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
index 39c079896b..5e77565562 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
@@ -189,14 +189,16 @@ public class MergeCommand extends GitCommand<MergeResult> {
mergeStrategy, null, null);
} else {
- repo.writeMergeCommitMsg(new MergeMessageFormatter().format(
- commits, head));
+ String mergeMessage = new MergeMessageFormatter().format(
+ commits, head);
+ repo.writeMergeCommitMsg(mergeMessage);
repo.writeMergeHeads(Arrays.asList(ref.getObjectId()));
ThreeWayMerger merger = (ThreeWayMerger) mergeStrategy
.newMerger(repo);
boolean noProblems;
Map<String, org.eclipse.jgit.merge.MergeResult<?>> lowLevelResults = null;
Map<String, MergeFailureReason> failingPaths = null;
+ List<String> unmergedPaths = null;
if (merger instanceof ResolveMerger) {
ResolveMerger resolveMerger = (ResolveMerger) merger;
resolveMerger.setCommitNames(new String[] {
@@ -206,6 +208,7 @@ public class MergeCommand extends GitCommand<MergeResult> {
lowLevelResults = resolveMerger
.getMergeResults();
failingPaths = resolveMerger.getFailingPaths();
+ unmergedPaths = resolveMerger.getUnmergedPaths();
} else
noProblems = merger.merge(headCommit, srcCommit);
@@ -230,13 +233,18 @@ public class MergeCommand extends GitCommand<MergeResult> {
headCommit.getId(), srcCommit.getId() },
MergeStatus.FAILED, mergeStrategy,
lowLevelResults, failingPaths, null);
- } else
+ } else {
+ String mergeMessageWithConflicts = new MergeMessageFormatter()
+ .formatWithConflicts(mergeMessage,
+ unmergedPaths);
+ repo.writeMergeCommitMsg(mergeMessageWithConflicts);
return new MergeResult(null,
merger.getBaseCommit(0, 1),
new ObjectId[] { headCommit.getId(),
srcCommit.getId() },
MergeStatus.CONFLICTING, mergeStrategy,
lowLevelResults, null);
+ }
}
}
} catch (IOException e) {