I would like to know how I can retrieve the list of changed files after a pull request.
I'm using this to get all the merged commits, but I want to know all the changed files.
Git git = new Git(localRepo);
PullCommand pullCmd = git.pull();
PullResult pullResult = pullCmd.call();
MergeResult mergeResult = pullResult.getMergeResult();
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
for (ObjectId mergedCommit : mergedCommits) {
// And now?
}
Building on the previous comments/questions:
Get the current head before you pull:
ObjectId oldHead = repository.resolve("HEAD^{tree}");
And after the pull again:
ObjectId head = repository.resolve("HEAD^{tree}");
Then you should be able to run the diff the same way as in How do I do the equivalent of "git diff --name-status" with jgit?:
ObjectReader reader = repository.newObjectReader();
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
oldTreeIter.reset(reader, oldHead);
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
newTreeIter.reset(reader, head);
List<DiffEntry> diffs= git.diff()
.setNewTree(newTreeIter)
.setOldTree(oldTreeIter)
.call();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With