package uk.ac.ic.wlgitbridge.bridge.repo;

import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
import org.eclipse.jgit.treewalk.WorkingTreeOptions;
import org.eclipse.jgit.util.FS;

import java.io.File;
import java.lang.reflect.Field;

/**
 * Created by winston on 08/10/2016.
 */
public class NoGitignoreIterator extends FileTreeIterator {

    private static final Field ignoreNodeField;

    static {
        try {
            ignoreNodeField = WorkingTreeIterator.class.getDeclaredField(
                    "ignoreNode"
            );
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
        ignoreNodeField.setAccessible(true);
    }

    public NoGitignoreIterator(Repository repo) {
        super(repo);
    }

    public NoGitignoreIterator(
            Repository repo,
            FileModeStrategy fileModeStrategy
    ) {
        super(repo, fileModeStrategy);
    }

    public NoGitignoreIterator(File root, FS fs, WorkingTreeOptions options) {
        super(root, fs, options);
    }

    public NoGitignoreIterator(
            File root,
            FS fs,
            WorkingTreeOptions options,
            FileModeStrategy fileModeStrategy
    ) {
        super(root, fs, options, fileModeStrategy);
    }

    protected NoGitignoreIterator(FileTreeIterator p, File root, FS fs) {
        super(p, root, fs);
    }

    protected NoGitignoreIterator(
            WorkingTreeIterator p,
            File root,
            FS fs,
            FileModeStrategy fileModeStrategy
    ) {
        super(p, root, fs, fileModeStrategy);
    }

    @Override
    protected void init(Entry[] list) {
        super.init(list);
        try {
            ignoreNodeField.set(this, null);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

}

@@ -76,16 +76,71 @@
 sitory;%0A
+import org.eclipse.jgit.treewalk.AbstractTreeIterator;%0A
 import o
@@ -1739,24 +1739,150 @@
 gy);%0A    %7D%0A%0A
+    // Note: the %60list%60 is a list of top-level entities in this directory,%0A    //       not a full list of files in the tree.%0A
     @Overrid
@@ -2113,10 +2113,402 @@
 %0A    %7D%0A%0A
+    // When entering a sub-directory, create a new instance of this class,%0A    // so we can also ignore gitignore specifications in sub-directories%0A    @Override%0A    protected AbstractTreeIterator enterSubtree() %7B%0A      String fullPath = getDirectory().getAbsolutePath() + %22/%22 + current().getName();%0A      return new NoGitignoreIterator(this, new File(fullPath), fs, fileModeStrategy);%0A    %7D%0A
 %7D%0A

Use the NoGitignoreIterator recursively