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