5

I have been using the Subclipse API to create a plug-in for Eclipse that listens for Subversion events that happen through the Subclipse plug-in. I am basically implementing a listener interface that then gets notified during run-time about the events going on.

I would like to do something similar, but for Git. It seems that EGit (which is built on JGit) will be the best option when it comes to utilizing another plug-in. I don't have much experience with their API though. I am wondering if anyone knows if EGit, or the underlying JGit, has a similar API interface for listening for Git events (such as commit, push, pull, etc.)?

Thanks!

jbranchaud
  • 5,909
  • 9
  • 45
  • 70

2 Answers2

6

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

Global listeners notified for all repositories:

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

Listeners on an invidiual 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 changes to the index, changes to the repository configuration, and changes to the repository's references (branches, tags, etc.).

You can find all the repositories registered in EGit through the following:

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

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

You can get a handle to a specific Repository object by creating a File for a path returned from the previous method and then call the following with that File:

org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().lookupRepository
Kevin Sawicki
  • 3,002
  • 1
  • 20
  • 18
0

So far there are no public listeners or extension points available. There are some extension points in the Commit dialog and also maybe other dialogs, but these are all non-public, and may be changed in the future. However, to track your interests, you should file an enhancement request at the Eclipse Bugzilla in the EGit project (i think, there are already some requests for similar features, so you can search them and vote for them).

dunni
  • 43,386
  • 10
  • 104
  • 99