-1

In TortoiseGit GUI,if we show log for a commit it is displaying the status as added since this file is added newly at that commit[![In this ,as i modified the file ,in status column it is showing as modified

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.

Byaku
  • 1,553
  • 1
  • 14
  • 24

1 Answers1

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