]> source.dussan.org Git - jgit.git/commitdiff
Initialize 'pathLen' field also for empty directories 54/34054/5
authorAndrey Loskutov <loskutov@gmx.de>
Mon, 29 Sep 2014 14:28:06 +0000 (16:28 +0200)
committerAndrey Loskutov <loskutov@gmx.de>
Thu, 23 Oct 2014 10:31:49 +0000 (12:31 +0200)
Bug: 445363
Change-Id: Ia8428af84fb61ba0d572374a19e8e8c55b138a63
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

index 51110b1d80f5b6195bf6f96f5fd686195272be82..ab4579009b41bf940d0b367a4f1a596d03b00146 100644 (file)
@@ -144,6 +144,43 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
                assertTrue(fti.eof());
        }
 
+       @Test
+       public void testEmptyIteratorOnEmptyDirectory() throws Exception {
+               String nonExistingFileName = "not-existing-file";
+               final File r = new File(trash, nonExistingFileName);
+               assertFalse(r.exists());
+               FileUtils.mkdir(r);
+
+               final FileTreeIterator parent = new FileTreeIterator(db);
+
+               while (!parent.getEntryPathString().equals(nonExistingFileName))
+                       parent.next(1);
+
+               final FileTreeIterator childIter = new FileTreeIterator(parent, r,
+                               db.getFS());
+               assertTrue(childIter.first());
+               assertTrue(childIter.eof());
+
+               String parentPath = parent.getEntryPathString();
+               assertEquals(nonExistingFileName, parentPath);
+
+               // must be "not-existing-file/", but getEntryPathString() was broken by
+               // 445363 too
+               String childPath = childIter.getEntryPathString();
+
+               // in bug 445363 the iterator wrote garbage to the parent "path" field
+               EmptyTreeIterator e = childIter.createEmptyTreeIterator();
+               assertNotNull(e);
+
+               // check if parent path is not overridden by empty iterator (bug 445363)
+               // due bug 445363 this was "/ot-existing-file" instead of
+               // "not-existing-file"
+               assertEquals(parentPath, parent.getEntryPathString());
+               assertEquals(parentPath + "/", childPath);
+               assertEquals(parentPath + "/", childIter.getEntryPathString());
+               assertEquals(childPath + "/", e.getEntryPathString());
+       }
+
        @Test
        public void testSimpleIterate() throws Exception {
                final FileTreeIterator top = new FileTreeIterator(trash, db.getFS(),
index 9eb428555720a2505f1557434f328bfdc05fb0d7..3d63d92542322413c5fdc6816a82fcd1e4b3e6f3 100644 (file)
@@ -668,6 +668,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
                ptr = 0;
                if (!eof())
                        parseEntry();
+               else if (pathLen == 0) // see bug 445363
+                       pathLen = pathOffset;
        }
 
        /**