summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorBernard Leach2011-04-29 05:42:10 (EDT)
committer Chris Aniszczyk2011-05-05 14:48:57 (EDT)
commit298486a7c320629de12f9506e0133686a7382b01 (patch)
tree4a3f545edd4fb769f89d33b4d071233a4da17d41
parente435f7de7748081945b02a0896dc54f4d6cc053c (diff)
downloadjgit-298486a7c320629de12f9506e0133686a7382b01.zip
jgit-298486a7c320629de12f9506e0133686a7382b01.tar.gz
jgit-298486a7c320629de12f9506e0133686a7382b01.tar.bz2
IndexDiff: conflicting files aren't properly shownrefs/changes/95/3295/3
Before this change any files in the conflicting set would also be listed in the the other IndexDiff Sets which is confusing. With this change a conflicting file will not be included in any of the other sets. Change-Id: Ife9f2652685220bcfddc1f9820423acdcd5acfdc Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java83
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java15
2 files changed, 88 insertions, 10 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 80c779d..77f1238 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
@@ -176,16 +176,91 @@ public class IndexDiffTest extends RepositoryTestCase {
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
diff.diff();
- assertEquals("[a, b]",
+ assertEquals("[b]",
new TreeSet<String>(diff.getChanged()).toString());
- assertEquals("[a]", diff.getAdded().toString());
+ assertEquals("[]", diff.getAdded().toString());
assertEquals("[]", diff.getRemoved().toString());
- assertEquals("[a]", diff.getMissing().toString());
- assertEquals("[a]", diff.getModified().toString());
+ assertEquals("[]", diff.getMissing().toString());
+ assertEquals("[]", diff.getModified().toString());
assertEquals("[a]", diff.getConflicting().toString());
}
@Test
+ public void testConflictingDeletedAndModified() 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 and delete "a"
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+ git.rm().addFilepattern("a").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("[]", new TreeSet<String>(diff.getChanged()).toString());
+ assertEquals("[]", diff.getAdded().toString());
+ assertEquals("[]", diff.getRemoved().toString());
+ assertEquals("[]", diff.getMissing().toString());
+ assertEquals("[]", diff.getModified().toString());
+ assertEquals("[a]", diff.getConflicting().toString());
+ }
+
+ @Test
+ public void testConflictingFromMultipleCreations() 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("b", "1\nb(side)\n3\n");
+ git.add().addFilepattern("b").call();
+ RevCommit secondCommit = git.commit().setMessage("side").call();
+
+ checkoutBranch("refs/heads/master");
+
+ writeTrashFile("b", "1\nb(main)\n3\n");
+ git.add().addFilepattern("b").call();
+ git.commit().setMessage("main").call();
+
+ 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("[]", new TreeSet<String>(diff.getChanged()).toString());
+ assertEquals("[]", diff.getAdded().toString());
+ assertEquals("[]", diff.getRemoved().toString());
+ assertEquals("[]", diff.getMissing().toString());
+ assertEquals("[]", diff.getModified().toString());
+ assertEquals("[b]", diff.getConflicting().toString());
+ }
+
+ @Test
public void testUnchangedSimple() throws IOException {
GitIndex index = new GitIndex(db);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
index b2c05ae..0b23b23 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
@@ -286,6 +286,15 @@ public class IndexDiff {
WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR,
WorkingTreeIterator.class);
+ if (dirCacheIterator != null) {
+ final DirCacheEntry dirCacheEntry = dirCacheIterator
+ .getDirCacheEntry();
+ if (dirCacheEntry != null && dirCacheEntry.getStage() > 0) {
+ conflicts.add(treeWalk.getPathString());
+ continue;
+ }
+ }
+
if (treeIterator != null) {
if (dirCacheIterator != null) {
if (!treeIterator.idEqual(dirCacheIterator)
@@ -324,12 +333,6 @@ public class IndexDiff {
modified.add(treeWalk.getPathString());
}
}
-
- final DirCacheEntry dirCacheEntry = dirCacheIterator
- .getDirCacheEntry();
- if (dirCacheEntry != null && dirCacheEntry.getStage() > 0) {
- conflicts.add(treeWalk.getPathString());
- }
}
}