aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Digtiar2011-07-18 01:33:30 (EDT)
committerChris Aniszczyk2011-08-21 16:53:02 (EDT)
commitc580c56c4def9639b603553b3d4cbc7117a30938 (patch)
treed3801915c28f1baa1b3215e9eb691021d6c64614
parente38cf2078d22e2c902a373371382ac8d82268f2d (diff)
downloadjgit-c580c56c4def9639b603553b3d4cbc7117a30938.zip
jgit-c580c56c4def9639b603553b3d4cbc7117a30938.tar.gz
jgit-c580c56c4def9639b603553b3d4cbc7117a30938.tar.bz2
Fix ClassCastException in MergeCommandrefs/changes/60/3860/5
Test was added which reproduce the ClassCastException when ours or theirs merge strategy is set to MergeCommand. Merger and MergeCommand were updated in order to avoid exception. Change-Id: I4c1284b4e80d82638d0677a05e5d38182526d196 Signed-off-by: Denys Digtiar <duemir@gmail.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java31
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java29
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteMapMerger.java25
6 files changed, 47 insertions, 51 deletions
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index d7f7ef1..06db49d 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -38,9 +38,11 @@ Import-Package: org.eclipse.jgit;version="[1.1.0,1.2.0)",
org.eclipse.jgit.treewalk.filter;version="[1.1.0,1.2.0)",
org.eclipse.jgit.util;version="[1.1.0,1.2.0)",
org.eclipse.jgit.util.io;version="[1.1.0,1.2.0)",
- org.junit;version="[4.0.0,5.0.0)",
org.hamcrest.core;version="[1.1.0,2.0.0)",
- org.hamcrest;version="[1.1.0,2.0.0)"
+ org.hamcrest;version="[1.1.0,2.0.0)",
+ org.junit;version="[4.4.0,5.0.0)",
+ org.junit.runner;version="[4.4.0,5.0.0)",
+ org.junit.experimental.theories;version="[4.4.0,5.0.0)"
Require-Bundle: com.jcraft.jsch;bundle-version="[0.1.37,0.2.0)"
Export-Package: org.eclipse.jgit.lib
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 7811706..1c682ca 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
@@ -62,8 +62,17 @@ import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Test;
+import org.junit.experimental.theories.DataPoints;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+@RunWith(Theories.class)
public class MergeCommandTest extends RepositoryTestCase {
+
+ public static @DataPoints
+ MergeStrategy[] mergeStrategies = MergeStrategy.get();
+
@Test
public void testMergeInItself() throws Exception {
Git git = new Git(db);
@@ -161,6 +170,28 @@ public class MergeCommandTest extends RepositoryTestCase {
}
}
+ @Theory
+ public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
+ throws Exception {
+ Git git = new Git(db);
+
+ RevCommit first = git.commit().setMessage("first").call();
+ createBranch(first, "refs/heads/side");
+
+ writeTrashFile("a", "a");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("second").call();
+
+ checkoutBranch("refs/heads/side");
+ writeTrashFile("b", "b");
+ git.add().addFilepattern("b").call();
+ git.commit().setMessage("third").call();
+
+ MergeResult result = git.merge().setStrategy(mergeStrategy)
+ .include(db.getRef(Constants.MASTER)).call();
+ assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+ }
+
@Test
public void testContentMerge() 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 5e77565..eca7e0b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
@@ -71,9 +71,9 @@ import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.merge.MergeMessageFormatter;
import org.eclipse.jgit.merge.MergeStrategy;
+import org.eclipse.jgit.merge.Merger;
import org.eclipse.jgit.merge.ResolveMerger;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
-import org.eclipse.jgit.merge.ThreeWayMerger;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.FileTreeIterator;
@@ -193,8 +193,7 @@ public class MergeCommand extends GitCommand<MergeResult> {
commits, head);
repo.writeMergeCommitMsg(mergeMessage);
repo.writeMergeHeads(Arrays.asList(ref.getObjectId()));
- ThreeWayMerger merger = (ThreeWayMerger) mergeStrategy
- .newMerger(repo);
+ Merger merger = mergeStrategy.newMerger(repo);
boolean noProblems;
Map<String, org.eclipse.jgit.merge.MergeResult<?>> lowLevelResults = null;
Map<String, MergeFailureReason> failingPaths = null;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
index 1bfa269..55ac999 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
@@ -134,7 +134,7 @@ public abstract class Merger {
* one or more sources could not be read, or outputs could not
* be written to the Repository.
*/
- public boolean merge(final AnyObjectId[] tips) throws IOException {
+ public boolean merge(final AnyObjectId... tips) throws IOException {
sourceObjects = new RevObject[tips.length];
for (int i = 0; i < tips.length; i++)
sourceObjects[i] = walk.parseAny(tips[i]);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java
index 9350adf..521f896 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java
@@ -84,7 +84,7 @@ public abstract class ThreeWayMerger extends Merger {
* @param id
* common base treeish; null to automatically compute the common
* base from the input commits during
- * {@link #merge(AnyObjectId, AnyObjectId)}.
+ * {@link #merge(AnyObjectId...)}.
* @throws IncorrectObjectTypeException
* the object is not a treeish.
* @throws MissingObjectException
@@ -101,33 +101,8 @@ public abstract class ThreeWayMerger extends Merger {
}
}
- /**
- * Merge together two tree-ish objects.
- * <p>
- * Any tree-ish may be supplied as inputs. Commits and/or tags pointing at
- * trees or commits may be passed as input objects.
- *
- * @param a
- * source tree to be combined together.
- * @param b
- * source tree to be combined together.
- * @return true if the merge was completed without conflicts; false if the
- * merge strategy cannot handle this merge or there were conflicts
- * preventing it from automatically resolving all paths.
- * @throws IncorrectObjectTypeException
- * one of the input objects is not a commit, but the strategy
- * requires it to be a commit.
- * @throws IOException
- * one or more sources could not be read, or outputs could not
- * be written to the Repository.
- */
- public boolean merge(final AnyObjectId a, final AnyObjectId b)
- throws IOException {
- return merge(new AnyObjectId[] { a, b });
- }
-
@Override
- public boolean merge(final AnyObjectId[] tips) throws IOException {
+ public boolean merge(final AnyObjectId... tips) throws IOException {
if (tips.length != 2)
return false;
return super.merge(tips);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteMapMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteMapMerger.java
index b0965d2..b335fbe 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteMapMerger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteMapMerger.java
@@ -55,7 +55,6 @@ import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.merge.Merger;
-import org.eclipse.jgit.merge.ThreeWayMergeStrategy;
import org.eclipse.jgit.merge.ThreeWayMerger;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -323,23 +322,13 @@ public class NoteMapMerger {
ObjectId theirsId = write(theirsList);
inserter.flush();
- ObjectId resultTreeId;
- if (nonNotesMergeStrategy instanceof ThreeWayMergeStrategy) {
- ThreeWayMerger m = ((ThreeWayMergeStrategy) nonNotesMergeStrategy)
- .newMerger(db, true);
- m.setBase(baseId);
- if (!m.merge(oursId, theirsId))
- throw new NotesMergeConflictException(baseList, oursList,
- theirsList);
-
- resultTreeId = m.getResultTreeId();
- } else {
- Merger m = nonNotesMergeStrategy.newMerger(db, true);
- if (!m.merge(new AnyObjectId[] { oursId, theirsId }))
- throw new NotesMergeConflictException(baseList, oursList,
- theirsList);
- resultTreeId = m.getResultTreeId();
- }
+ Merger m = nonNotesMergeStrategy.newMerger(db, true);
+ if (m instanceof ThreeWayMerger)
+ ((ThreeWayMerger) m).setBase(baseId);
+ if (!m.merge(oursId, theirsId))
+ throw new NotesMergeConflictException(baseList, oursList,
+ theirsList);
+ ObjectId resultTreeId = m.getResultTreeId();
AbbreviatedObjectId none = AbbreviatedObjectId.fromString("");
return NoteParser.parse(none, resultTreeId, reader).nonNotes;
}