How to get current git branch inside StartActivity

I want to fetch current git branch after the Intellij idea has been up and a project is selected.

If the branch is changed then get the changed branch name.

 

Thanks,

Vikash

6 comments
Comment actions Permalink

Check GitBranchUtil.getCurrentRepository().getCurrentBranch().

If you want to fetch, you can use GitFetcher. However, it shows a success notification, so maybe it is not the best candidate for your task of silent implicit fetch. To fetch manually, call Git.fetch() (see GitFetcher implementation for details).

1
Comment actions Permalink

Thanks Kirill for the to the solution.

I tried the above-mentioned approach but it says "Class GitBranchUtil not found". Many of the APIs which I have used so far never asked to attach any library because all are available in the plugin development. If I try to attach the jar file it's still complaining.

What mistake I am doing I have no clue. 

Regards,

Vikash

0
Comment actions Permalink

I Have the same question. Is a libary needed or recommended for GIT-Actions, especially for intellij? I use JGIT.

And how to recognize if the branch was changed. is there a callback or similar?

Thanks!

0
Comment actions Permalink

Nevermind, figured it out.

The plugin git2idea (aka IntelliJ-idea git integration plugin) has the API you mentioned in the answer. And I add the git2idea jar file in the plugin sdk classpath and added the <deped> tag in the plugin.xml file. Here's the doc I followed http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html.

As of now my requirement does not have to look for branch change but I found something useful in order to find solution for my problem. May be of your use, https://github.com/zielu/GitToolBox/blob/12a2a78ccf31dad0177cae34a1a1fa75c4ad1610/GitToolBox/src/zielu/gittoolbox/repo/GtRepositoryManager.java

Let me know if it works for you.

Thank you,

0
Comment actions Permalink

Please note that GitToolBox is a 3-party plugin, and its GitRepositoryManager != the one from git4idea.

 

@ 

Currently there is no API to listen to branch changes. There is API for any change in repository: take a look at GitRepository.GIT_REPO_CHANGE and its usages. You probably should remember your current branch, listen to GIT_REPO_CHANGE events, get GitRepository.getCurrentBranch() and compare it with your remembered value.

0
Comment actions Permalink

Great - Thank you guys - i give it a try tomorrow :-)

0

Please sign in to leave a comment.