How to create a diff with JGIT without repository?

Viewed 95

For my use case I need a Git diff of two Files without creating any Git repo. I am looking for a possibility to get the result of git diff --no-index <file-1> <file-2> in JGit. I've tried to create the diff described in this post, but it does not return the desired result.

This code...

...
OutputStream out = new ByteArrayOutputStream();
RawText rawTextOld = new RawText(getBytesOld());
RawText rawTextNew = new RawText(getBytesNew());
EditList diffList = new EditList();
diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rawTextOld, rawTextNew));
DiffFormatter diffFormatter = new DiffFormatter(out);
diffFormatter.format(diffList, rawTextOld, rawTextNew);
System.out.println(out.toString());
...

...produces the following output:

@@ -5,5 +5,5 @@
 uvloop
 aiohttp
 cchardet
-aiodns
+aiodnstest

But what I need is something like this (similiar to git diff --no-index <file-1> <file-2>):

diff --git a/requirements.txt b/requirements.txt
index c3f75dc..2cda10e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,5 +5,5 @@
 uvloop
 aiohttp
 cchardet
-aiodns
+aiodnstest

Does anyone know how I can create this output with JGit?

0 Answers
Related