Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a listener for Git events through the EGit/JGit plug-in?

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!

like image 686
jbranchaud Avatar asked Oct 27 '11 14:10

jbranchaud


People also ask

What does EGit do?

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.

How to push local branch to remote Eclipse?

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.

How to open Git repository view in Eclipse?

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.


1 Answers

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
like image 123
Kevin Sawicki Avatar answered Nov 01 '22 09:11

Kevin Sawicki