4

Use JGit. Need to know the difference in the branches. How to run a command JGit API: git diff --name-status ..origin

Mikhail
  • 53
  • 1
  • 8
  • What specifically are you having a problem with? Have you looked at the [JGit API](http://download.eclipse.org/jgit/docs/latest/apidocs/org/eclipse/jgit/api/Git.html) at all? – robinst Aug 21 '13 at 11:24
  • Yes, I have used the JGit API. I don't understand, how to run the command `git diff --name-status ..origin` with `DiffCommand` – Mikhail Aug 22 '13 at 10:19

1 Answers1

3

You can use the DiffCommand by creating AbstractTreeIterator instaces for the branches and then use the DiffCommand to return you a list of differences between the two branches:

// the diff works on TreeIterators, we prepare two for the two branches
AbstractTreeIterator oldTreeParser = prepareTreeParser(repository, "refs/heads/oldbranch");
AbstractTreeIterator newTreeParser = prepareTreeParser(repository, "refs/heads/master");

// then the procelain diff-command returns a list of diff entries
List<DiffEntry> diff = new Git(repository).diff().setOldTree(oldTreeParser).setNewTree(newTreeParser).call();
for(DiffEntry entry : diff) {
    System.out.println("Entry: " + entry);
}

The full example including creating the AbstractTreeIterator can now be found as part of my jgit-cookbook

centic
  • 15,565
  • 9
  • 68
  • 125