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!
EGit is an Eclipse Team provider for the Git version control system. Git is a distributed SCM, which means every developer has a full copy of all history of every revision of the code, making queries against the history very fast and versatile.
First, right click the project node and navigate to Team=> Push… . Enter the repository you want to push your branches to (the default for this will be the same as the Fetch default if you didn't configure a Push default) and hit Next.
Open the Git repository view. Use Ctrl+3 (or Cmd+3) and type Git Repositories in the dialog to open the Git repositories view. This view shows you the Git repositories you can work with in Eclipse and allows you to add existing repositories to Eclipse, create or clone repositories.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With