I\'d like to use JGit to display a list of all files and folders for the head revision. I\'m able to list all files using TreeWalk, but this does not list folders.
Here
You need to set recursive to false (see documentation) and then walk like this:
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(false);
while (treeWalk.next()) {
if (treeWalk.isSubtree()) {
System.out.println("dir: " + treeWalk.getPathString());
treeWalk.enterSubtree();
} else {
System.out.println("file: " + treeWalk.getPathString());
}
}
Git does not track directories of their own. You can only derive non-empty directory names from the path string you get from the TreeWalk.
See the Git FAQ (search for 'empty directory') for a detailed explanation and possible workarounds.