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

0
6 comments

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).

2

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

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

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

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

 

@Michael Wölk 

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

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

0

Please sign in to leave a comment.