Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top