Beispiel #1
0
 public static List<File> getNotIgnoredFilesOfRepo(File directory) throws GitException {
   Git git = openRepository(directory);
   Repository repo = null;
   repo = git.getRepository();
   List<File> foundFiles = new ArrayList<>();
   TreeWalk treeWalk = null;
   try {
     treeWalk = new TreeWalk(repo);
     FileTreeIterator tree = new FileTreeIterator(repo);
     treeWalk.addTree(tree);
     treeWalk.setRecursive(false);
     while (treeWalk.next()) {
       WorkingTreeIterator iterator = treeWalk.getTree(0, WorkingTreeIterator.class);
       if (!iterator.isEntryIgnored())
         if (treeWalk.isSubtree()) {
           treeWalk.enterSubtree();
         } else {
           File file = new File(directory, treeWalk.getPathString());
           foundFiles.add(file);
         }
     }
   } catch (IOException e) {
     throw new GitException("Listing of non-ignored files in " + directory + " failed", e);
   } finally {
     if (treeWalk != null) treeWalk.close();
   }
   return foundFiles;
 }
  @Override
  public void close() {

    repository.close();
    git.close();
    treeWalk.close();
    revWalk.close();
    reader.close();
  }