]> source.dussan.org Git - jgit.git/commitdiff
Do not report ignored directories as untracked 41/11141/2
authorMatthias Sohn <matthias.sohn@sap.com>
Thu, 28 Feb 2013 22:47:44 +0000 (23:47 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 18 Jan 2014 23:20:42 +0000 (00:20 +0100)
Change-Id: I7e3f6b9fb1ac4b99d2cc9a78c63aad86f4fa5744
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java

index 51ba5f13ea1266d0aef965bf59d02a4f58b6fab1..64e72e8fc7e801218a406c3052b2581c2eafb181 100644 (file)
@@ -467,6 +467,53 @@ public class IndexDiffTest extends RepositoryTestCase {
                                diff.getUntrackedFolders());
        }
 
+       /**
+        * Test that ignored folders aren't listed as untracked
+        *
+        * @throws Exception
+        */
+       @Test
+       public void testUntrackedNotIgnoredFolders() throws Exception {
+               Git git = new Git(db);
+
+               IndexDiff diff = new IndexDiff(db, Constants.HEAD,
+                               new FileTreeIterator(db));
+               diff.diff();
+               assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
+
+               writeTrashFile("readme", "");
+               writeTrashFile("sr/com/X.java", "");
+               writeTrashFile("src/com/A.java", "");
+               writeTrashFile("src/org/B.java", "");
+               writeTrashFile("srcs/org/Y.java", "");
+               writeTrashFile("target/com/A.java", "");
+               writeTrashFile("target/org/B.java", "");
+               writeTrashFile(".gitignore", "/target\n/sr");
+
+               git.add().addFilepattern("readme").addFilepattern(".gitignore")
+                               .addFilepattern("srcs/").call();
+               git.commit().setMessage("initial").call();
+
+               diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
+               diff.diff();
+               assertEquals(new HashSet<String>(Arrays.asList("src")),
+                               diff.getUntrackedFolders());
+
+               git.add().addFilepattern("src").call();
+               writeTrashFile("sr/com/X1.java", "");
+               writeTrashFile("src/tst/A.java", "");
+               writeTrashFile("src/tst/B.java", "");
+               writeTrashFile("srcs/com/Y1.java", "");
+               deleteTrashFile(".gitignore");
+
+               diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
+               diff.diff();
+               assertEquals(
+                               new HashSet<String>(Arrays.asList("srcs/com", "sr", "src/tst",
+                                               "target")),
+                               diff.getUntrackedFolders());
+       }
+
        @Test
        public void testAssumeUnchanged() throws Exception {
                Git git = new Git(db);
index 1b231cce9dfbb8fb8087c1335b6190b8215894d8..c3323b8684784e8212435c660a8b34667d0270ca 100644 (file)
@@ -132,6 +132,7 @@ public class IndexDiffFilter extends TreeFilter {
                        IncorrectObjectTypeException, IOException {
                final int cnt = tw.getTreeCount();
                final int wm = tw.getRawMode(workingTree);
+               WorkingTreeIterator wi = workingTree(tw);
                String path = tw.getPathString();
 
                DirCacheIterator di = tw.getTree(dirCache, DirCacheIterator.class);
@@ -148,7 +149,8 @@ public class IndexDiffFilter extends TreeFilter {
                        // contain only untracked files and add it to
                        // untrackedParentFolders. If we later find tracked files we will
                        // remove it from this list
-                       if (FileMode.TREE.equals(wm)) {
+                       if (FileMode.TREE.equals(wm)
+                                       && !(honorIgnores && wi.isEntryIgnored())) {
                                // Clean untrackedParentFolders. This potentially moves entries
                                // from untrackedParentFolders to untrackedFolders
                                copyUntrackedFolders(path);
@@ -179,7 +181,6 @@ public class IndexDiffFilter extends TreeFilter {
                // we can avoid returning a result here, but only if its not in any
                // other tree.
                final int dm = tw.getRawMode(dirCache);
-               WorkingTreeIterator wi = workingTree(tw);
                if (dm == FileMode.TYPE_MISSING) {
                        if (honorIgnores && wi.isEntryIgnored()) {
                                ignoredPaths.add(wi.getEntryPathString());