I am struggling to get the changed File list for Each commit using Jgit from Github repository. please find my sample code and output for your references. We are expecting for each commit we want to know what are files are modified or added or deleted.
File gitWorkDir = new File("D:/Eka_App/Log_Audit");
Git git = Git.open(gitWorkDir);
Repository repo = git.getRepository();
String path = "Database";
Iterator<RevCommit> revCommits = git.log().addPath(path).call()
.iterator();
while (revCommits.hasNext()) {
RevCommit commit = revCommits.next();
System.out.println("commit descr: " + commit.getShortMessage()
+ ", Commit id : " + commit.getId() + ",Commit time: "
+ commit.getCommitTime() + ", Auther: "
+ commit.getAuthorIdent());
RevTree tree = commit.getTree();
TreeWalk treeWalk = new TreeWalk(repo);
treeWalk.addTree(tree); // option 1
treeWalk.setRecursive(false);
treeWalk.setPostOrderTraversal(false);
while (treeWalk.next()) {
if (treeWalk.getPathString().contains("Database")) {
if (treeWalk.isSubtree()) {
// System.out.println("dir: " +
// treeWalk.getPathString());
treeWalk.enterSubtree();
} else {
System.out.println("file: " + treeWalk.getPathString());
}
}
}
}