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);
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);
// 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);
// 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());