aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
diff options
context:
space:
mode:
authorBernard Leach <leachbj@bouncycastle.org>2011-04-20 07:51:40 +1000
committerChris Aniszczyk <caniszczyk@gmail.com>2011-04-19 17:11:01 -0500
commit1a867d10b974cab4d43d77f5b392f4f07807ebd8 (patch)
tree9a9b47b5568b5d4ec01dfd54c4952d2f0dae279c /org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
parentb69284f72d717f50981c822edbff1dc3313cdd58 (diff)
downloadjgit-1a867d10b974cab4d43d77f5b392f4f07807ebd8.tar.gz
jgit-1a867d10b974cab4d43d77f5b392f4f07807ebd8.zip
Added support to IndexDiff to return information on conflicts
Change-Id: I43c13eb72a44f80135c93525fce0c0280b0e64a2 Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
index d98358746b..80c779ddfd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
@@ -50,11 +50,16 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
+import java.util.TreeSet;
import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.MergeResult;
+import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.eclipse.jgit.merge.MergeStrategy;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.junit.Test;
@@ -140,6 +145,47 @@ public class IndexDiffTest extends RepositoryTestCase {
}
@Test
+ public void testConflicting() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "1\na\n3\n");
+ writeTrashFile("b", "1\nb\n3\n");
+ git.add().addFilepattern("a").addFilepattern("b").call();
+ RevCommit initialCommit = git.commit().setMessage("initial").call();
+
+ // create side branch with two modifications
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+ writeTrashFile("a", "1\na(side)\n3\n");
+ writeTrashFile("b", "1\nb\n3\n(side)");
+ git.add().addFilepattern("a").addFilepattern("b").call();
+ RevCommit secondCommit = git.commit().setMessage("side").call();
+
+ // update a on master to generate conflict
+ checkoutBranch("refs/heads/master");
+ writeTrashFile("a", "1\na(main)\n3\n");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("main").call();
+
+ // merge side with master
+ MergeResult result = git.merge().include(secondCommit.getId())
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
+
+ FileTreeIterator iterator = new FileTreeIterator(db);
+ IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
+ diff.diff();
+
+ assertEquals("[a, b]",
+ new TreeSet<String>(diff.getChanged()).toString());
+ assertEquals("[a]", diff.getAdded().toString());
+ assertEquals("[]", diff.getRemoved().toString());
+ assertEquals("[a]", diff.getMissing().toString());
+ assertEquals("[a]", diff.getModified().toString());
+ assertEquals("[a]", diff.getConflicting().toString());
+ }
+
+ @Test
public void testUnchangedSimple() throws IOException {
GitIndex index = new GitIndex(db);