How to create a listener for Git events through the EGit / JGit plugin?

I use the Subclipse API to create a plugin for Eclipse that listens for Subversion events that occur through the Subclipse plug-in. I basically implement a listener interface, which then receives a notification during the execution of events.

I would like to do something similar, but for Git. It seems that EGit (which is built on JGit) would be the best option when it comes to using another plugin. However, I do not have much experience with their API. I am wondering if anyone knows if EGit or the underlying JGit has a similar API for listening for Git events (e.g. commit, push, pull, etc.)?

Thank!

+5
source share
2 answers

You can register listeners through JGit for all repositories or individual repositories using the following methods:

Global listeners are notified of all repositories:

org.eclipse.jgit.lib.Repository.getGlobalListenerList().addIndexChangedListener
org.eclipse.jgit.lib.Repository.getGlobalListenerList().addConfigChangedListener
org.eclipse.jgit.lib.Repository.getGlobalListenerList().addRefsChangedListener

Listeners in an invisible repository:

org.eclipse.jgit.lib.Repository.getListenerList().addIndexChangedListener
org.eclipse.jgit.lib.Repository.getListenerList().addConfigChangedListener
org.eclipse.jgit.lib.Repository.getListenerList().addRefsChangedListener

These listeners support events for changing the index, changing the configuration of the repository, and changing links to repositories (branches, tags, etc.).

You can find all repositories registered with EGit as follows:

Get absolute paths to all repositories present in EGit by calling:

org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil().getConfiguredRepositories()

You can get the handle to a specific repository object by creating a file for the path returned from the previous method, and then call the following using this file:

org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().lookupRepository
+6
source

. Commit , , , , . , , Eclipse Bugzilla EGit (, , ).

0

All Articles