Reputation: 173
How can I traverse with jgit all content of an specific commit from an specific branch?
ObjectId commitId = repository.resolve(currentCommit.getCommitHash());
RevWalk revWalk = new RevWalk(repository);
RevCommit commit = revWalk.parseCommit(commitId);
RevTree tree = commit.getTree();
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(currentPath));
if (!treeWalk.next()) {
throw new IllegalStateException(
"Did not find expected file README.md");
}
This code retrieve me a special file from the commit but I want traverse all content of an commit.
Upvotes: 1
Views: 481
Reputation: 31407
See this answer, it lists files and folders. You can use setRecursive(true)
and leave off the isSubtree
branch when you are just interested in file paths.
Upvotes: 2