Jeewantha
Jeewantha

Reputation: 985

How to get the list of about-to-be-commited files in JGIT?

I need to write a precommit hook for GIT where the about to be commited files are checked to see if they are formatted according to a specific eclipse formatter. For this I need to get the list of the files which are not yet commited and their contents. Can this be done using JGIT?

Upvotes: 1

Views: 217

Answers (1)

Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 56

AFAIK, commit hooks aren't yet implemented in JGit. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=299315

However, for examining the index, you can use the DirCache class. DirCache.read(Repository) returns the index for the given repository. You can then either use a TreeWalk to iterate over the entries or use getEntryCount() and getEntry().
You may also want to look at the unit tests to get further pointers on how to use the API.

Upvotes: 2

Related Questions