]> source.dussan.org Git - jgit.git/commitdiff
Ignore removed files with an assume-valid index entry 12/9412/2
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 1 Jan 2013 14:50:15 +0000 (15:50 +0100)
committerChris Aniszczyk <zx@twitter.com>
Fri, 4 Jan 2013 01:02:59 +0000 (19:02 -0600)
Bug: 347067
Change-Id: I5472e69dc77e26b5f248a4a04295775cf5051215
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java

index 2441032eb92b423a4fa924aa321156c6fba037dc..1f25700dd4ed7d69e7a7c80c5162144b89671d6b 100644 (file)
@@ -466,19 +466,23 @@ public class IndexDiffTest extends RepositoryTestCase {
                git.add().addFilepattern(path).call();
                String path2 = "file2";
                writeTrashFile(path2, "content");
-               git.add().addFilepattern(path2).call();
+               String path3 = "file3";
+               writeTrashFile(path3, "some content");
+               git.add().addFilepattern(path2).addFilepattern(path3).call();
                git.commit().setMessage("commit").call();
                assumeUnchanged(path2);
+               assumeUnchanged(path3);
                writeTrashFile(path, "more content");
-               writeTrashFile(path2, "more content");
+               deleteTrashFile(path3);
 
                FileTreeIterator iterator = new FileTreeIterator(db);
                IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
                diff.diff();
-               assertEquals(1, diff.getAssumeUnchanged().size());
+               assertEquals(2, diff.getAssumeUnchanged().size());
                assertEquals(1, diff.getModified().size());
                assertEquals(0, diff.getChanged().size());
                assertTrue(diff.getAssumeUnchanged().contains("file2"));
+               assertTrue(diff.getAssumeUnchanged().contains("file3"));
                assertTrue(diff.getModified().contains("file"));
 
                git.add().addFilepattern(".").call();
@@ -486,10 +490,11 @@ public class IndexDiffTest extends RepositoryTestCase {
                iterator = new FileTreeIterator(db);
                diff = new IndexDiff(db, Constants.HEAD, iterator);
                diff.diff();
-               assertEquals(1, diff.getAssumeUnchanged().size());
+               assertEquals(2, diff.getAssumeUnchanged().size());
                assertEquals(0, diff.getModified().size());
                assertEquals(1, diff.getChanged().size());
                assertTrue(diff.getAssumeUnchanged().contains("file2"));
+               assertTrue(diff.getAssumeUnchanged().contains("file3"));
                assertTrue(diff.getChanged().contains("file"));
                assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
        }
index 4e44a76c995335a2678f7c13a95e37f9adc4b293..1b231cce9dfbb8fb8087c1335b6190b8215894d8 100644 (file)
@@ -48,6 +48,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
 
+import org.eclipse.jgit.dircache.DirCacheEntry;
 import org.eclipse.jgit.dircache.DirCacheIterator;
 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
 import org.eclipse.jgit.errors.MissingObjectException;
@@ -133,6 +134,14 @@ public class IndexDiffFilter extends TreeFilter {
                final int wm = tw.getRawMode(workingTree);
                String path = tw.getPathString();
 
+               DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
+               if (di != null) {
+                       DirCacheEntry dce = di.getDirCacheEntry();
+                       if (dce != null)
+                               if (dce.isAssumeValid())
+                                       return false;
+               }
+
                if (!tw.isPostOrderTraversal()) {
                        // detect untracked Folders
                        // Whenever we enter a folder in the workingtree assume it will
@@ -153,7 +162,7 @@ public class IndexDiffFilter extends TreeFilter {
                        // it.
                        for (int i = 0; i < cnt; i++) {
                                int rmode = tw.getRawMode(i);
-                               if (i != workingTree && rmode != 0
+                               if (i != workingTree && rmode != FileMode.TYPE_MISSING
                                                && FileMode.TREE.equals(rmode)) {
                                        untrackedParentFolders.clear();
                                        break;
@@ -171,14 +180,14 @@ public class IndexDiffFilter extends TreeFilter {
                // other tree.
                final int dm = tw.getRawMode(dirCache);
                WorkingTreeIterator wi = workingTree(tw);
-               if (dm == 0) {
+               if (dm == FileMode.TYPE_MISSING) {
                        if (honorIgnores && wi.isEntryIgnored()) {
                                ignoredPaths.add(wi.getEntryPathString());
                                int i = 0;
                                for (; i < cnt; i++) {
                                        if (i == dirCache || i == workingTree)
                                                continue;
-                                       if (tw.getRawMode(i) != 0)
+                                       if (tw.getRawMode(i) != FileMode.TYPE_MISSING)
                                                break;
                                }
 
@@ -209,7 +218,6 @@ public class IndexDiffFilter extends TreeFilter {
                // Only one chance left to detect a diff: between index and working
                // tree. Make use of the WorkingTreeIterator#isModified() method to
                // avoid computing SHA1 on filesystem content if not really needed.
-               DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
                return wi.isModified(di.getDirCacheEntry(), true);
        }