1

I can get an indication that a file was Added, Modified or Deleted using the git log --pretty=format: --name-status command.

What part of the JGit API would give me access to this status?

For example, the jGit cookbook does give an example of getting file modes:

TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(false);
treeWalk.setFilter(PathFilter.create("src"));
if (!treeWalk.next()) {
    throw new IllegalStateException("Did not find expected file 'README.md'");
}

// FileMode now indicates that this is a directory, i.e. FileMode.TREE.equals(fileMode) holds true
FileMode fileMode = treeWalk.getFileMode(0);

Where your can get info of the type of file from:

FileMode.REGULAR_FILE

I have looked at the API documentation at org.eclipse.jgit.lib.AnyObjectId etc. but am not finding an obvious path to where the API would provide information about the operation being an Add, Delete or Modification on the file in the commit.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Interition
  • 381
  • 2
  • 15
  • The `FileMode` is the wrong place to look at - it just tells you whether a tree entry represents a file, a directory or a link. You can only tell if a file was added changed or removed when comparing two commits. Thus I think what you are looking for [was asked here](http://stackoverflow.com/questions/28785364/jgit-list-of-files-changed-between-commits/28793479#28793479). – Rüdiger Herrmann Mar 02 '15 at 16:28
  • bingo. thanks very much for the quick response. – Interition Mar 02 '15 at 18:45
  • Glad to see your problem solved. I you don't object I will flag this question as duplicate. – Rüdiger Herrmann Mar 02 '15 at 19:32
  • I still think it deserves a direct answer from me once I have done it. – Interition Mar 03 '15 at 07:23
  • Sorry, I was too fast and already flagged the post as duplicate. But I think the moderators will read your comment and reject my suggestion. – Rüdiger Herrmann Mar 03 '15 at 07:27
  • just to confirm. the other answer implied you can only get the Add,Delete,Modified attribute from the Diff between two commits? If so this can be closed as a dupe. – Interition Mar 03 '15 at 11:38
  • Right, a commit can be seen as a snapshot of your working directory and thus changes (add, delete, modify) can only be made out when comparing commits (i.e. diff). – Rüdiger Herrmann Mar 03 '15 at 11:50

0 Answers0