In my local git repository,i have more than one commits for a file. How can i get status/action has been performed on that commit.I mean, how can i know on a particular commit,is that file added newly or is it been modified or is it been labeled..i want the correct eclipse API to get the above details.
Asked
Active
Viewed 57 times
-1
-
could you please explain more ? – Byaku May 05 '16 at 03:12
-
As they showing in the status column of attached image,i want get the API in JGIT – Renganathan Selvaraju May 10 '16 at 13:28
-
did you check http://stackoverflow.com/questions/23508315/git-status-does-not-show-changes-when-creating-repo-in-jgit – Byaku May 10 '16 at 13:46
-
could you check https://github.com/centic9/jgit-cookbook ? – Byaku May 10 '16 at 13:54
-
Status status = git.status().call(); i am able to get only untracked files.added, removed, modified files are empty. – Renganathan Selvaraju May 10 '16 at 14:59
1 Answers
0
Get git file status by using JGit
// find the HEAD
ObjectId lastCommitId = existingRepo.resolve(Constants.HEAD);
// a RevWalk allows to walk over commits based on some filtering that is defined
try (RevWalk revWalk = new RevWalk(existingRepo)) {
RevCommit commit = revWalk.parseCommit(lastCommitId);
// and using commit's tree find the path
RevTree tree = commit.getTree();
// now try to find a specific file
try (TreeWalk treeWalk = new TreeWalk(existingRepo)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create("TestProject/test1"));
if (!treeWalk.next()) {
throw new IllegalStateException("Did not find expected file");
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = existingRepo.open(objectId);
// and then one can the loader to read the file
loader.copyTo(System.out);
// Get status
Git git = new Git(existingRepo);
StatusCommand status = git.status().addPath(treeWalk.getPathString());
System.out.println("Not Modified : " + status.call().getModified().isEmpty());
}
Byaku
- 1,553
- 1
- 14
- 24