|JGIT -> How to apply a patch to a file outside a repository [message #1288082]
||Tue, 08 April 2014 09:02
| Juan Pablo Barani
Registered: April 2014
I am building a solution to update files for a certain software in Java. I want to create something like the diff/patch Unix functionality, but with Java, for files that are directly in a FS, that is, outside a repository.|
At the moment, I could easily get a Diff with JGit by using the following code:
public static EditList computeDifferencesGit(final File p_fileOld,
final File p_fileNew) throws IOException
RawText l_contentFileOld = new RawText(p_fileOld);
RawText l_contentFileNew = new RawText(p_fileNew);
EditList l_listDiffs = new EditList();
l_listDiffs.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, l_contentFileOld, l_contentFileNew));
String l_strUnidiff = _getUnidiff(l_contentFileOld, l_contentFileNew, l_listDiffs);
System.out.println("UNIDIFF:\n" + l_strUnidiff);
However, I would like to apply the results of that diff to a third file as a patch.
I investigated and found there is an ApplyCommand class in JGit package. However, to instantiate it, I think I need a repository, which I don't have.
Any idea about how can I apply the patch to the file?
Powered by FUDForum
. Page generated in 0.02423 seconds