I need to store the contents of a commit, this would be the difference from eg. master to the latest commit, in a string.
How to show changes between commits with JGit The bottom answer is very similar to what I want
This is the code from the link
RevCommit headCommit = getHeadCommit(repository);
RevCommit diffWith = headCommit.getParent(0);
FileOutputStream stdout = new FileOutputStream(FileDescriptor.out);
try (DiffFormatter diffFormatter = new DiffFormatter(stdout)) {
diffFormatter.setRepository(repository);
for (DiffEntry entry : diffFormatter.scan(diffWith, headCommit)) {
diffFormatter.format(diffFormatter.toFileHeader(entry));
}
}
diffFormatter.format(diffFormatter.toFileHeader(entry));
The format() method is void, and there doesnt seem to be a way to return a string or some sort of outputstream.
I would expect there to be something along the lines of
String commitDiff = diffFormatter.getCommitContents(entry).toString();
I understand this doesnt exist in the library, but there must be something that can put the contents of a commit into something that can be turned into a String