1

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.

Roney Michael
  • 3,964
  • 5
  • 30
  • 45
Sadik Hasan
  • 173
  • 3
  • 18

1 Answers1

2

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.

Community
  • 1
  • 1
robinst
  • 30,027
  • 10
  • 102
  • 108