Is there documentation about available events?

im trying to write a plugin on basis of Git4Idea which needs to obtain a GitRepository Object to retrieve the current branch im currently on.
First i tried to get a Repository directly from the GitRepositoryManager i obtianed via ApplocationManager.getApplication.getComponent(..) but its array Holfing the repositories for my test project was always empty.
The ProjectLevelVcsManager wasnt helpful either.
Then i gave up to get the GitRepository directly and hoped i could find the matching GitRepository if i registered my component as a GitRepositoryChangeListener. Yet i run into an NPE if i call getCurrentBranch on the GitRepository object passed to the method, as its myInfo attribute is set to null in the first cycle of repositoryChanged calls (which very very bad design IMHO).
So my only chance here is to wrap the call to repository.getCurrentBranch() into a try/catch block and hope the listener will be called later again when the myInfo field finally isnt null anymore.

So my question is: is there any event i can listen for which is emited late enough so everything regarding VCS is initialized so i can use the GitRepository-object from somewhere and use it without running into exceptions? And are the available events documented somewhere?

Thanks in advance


Hi Malte,

ServiceManager.getService(project, GitRepositoryManager.class) should return a valid instance of the GitRepositoryManager for the given project.
It will contain GitRepositories for all Git roots registered in the ProjectLevelVcsManager (i. e. in Settings | Version Control table).
You shouldn't create GitRepository directly.

To make sure that GitRepositoryManager is ready when you want to ask it about repositories, declare it as a dependency for your component or service. For this just expect the instance of GitRepositoryManager in your component/service constructor.


Hi Kirill,

unfortunately the problem persist.
As you suggested i decalled the GitRepositoryManager as a dependency by expecting it as a constructor-parameter. But when i call getRepositories() on the instance passes to the constructor i get an empty list.
The first time when i get a non empty list is a "long time" after the application started.
For testing reasons i called getRepositories() inside the repositoryChanged-method provided by the GitRepositoryChangeListener.
The method is called on startup of the application. The list will be empty this time. When i change the git-branch later through the applicaiton and repositoryChanged is called again its the first time i am able to retrieve a non empty List from getRepositories() :-/

Any ideas about a hook i can use to get the list of GitRepository as early as possible?



(Sorry for the late answer -- i hadn't had time befor :) )


If you look into source of the AbstractRepositoryManager, you'll see that the repository map is populated in updateRepositoriesCollection()
This method is called from directoryMappingChanged(), i. e. when version control roots mappings are updated, as well as on the project load (when the mappings are updated initially).
(these mappings is internal representation of data in the Settings | Version Control table)
You can place a breakpoint inside updateRepositoriesCollection() and check if it is called on startup, and if repositories are collected correctly inside this method.


Well yes, the map is populatd, but still the branch of the "myInfo" variable in the GitRepositoryManagerImpl is set to null...


Please sign in to leave a comment.