To get current branch name:
git4idea.repo.GitRepositoryManager.getInstance(myProject).getRepositories()gitRepository.getCurrentBranch().getName();
To get all commits in a local branch (query `git log <branch name>`)
git4idea.history.GitHistoryUtils#history(project, gitRepository.getRoot(), branchName);
Thanks for the reply.
I added the code to get branch name, and it compiled OK, but failed at testing:
git4idea/repo/GitRepositoryManagerjava.lang.NoClassDefFoundError: git4idea/repo/GitRepositoryManager
Here is the code:
GitRepositoryManager gitRepositoryManager = GitRepositoryManager.getInstance(project);List<GitRepository> repositories = gitRepositoryManager.getRepositories();for (GitRepository repository : repositories) { System.out.println("Current Branch Name: " + repository.getCurrentBranch().getName()); System.out.println("Current Branch Full Name: " + repository.getCurrentBranch().getFullName());}
Here is part of build.gradle:
apply plugin: 'idea'apply plugin: 'org.jetbrains.intellij'apply plugin: 'java'apply plugin: 'jacoco'compileJava { options.compilerArgs << '-Xlint:unchecked' options.compilerArgs << '-Werror' options.fork = true options.forkOptions.executable = 'javac' sourceCompatibility = 1.8 targetCompatibility = 1.8}intellij { version '2017.3.2' //or a full list of IntelliJ IDEA releases please see https://www.jetbrains.com/intellij-repository/releases plugins 'git4idea'}
You need to modify your `plugin.xml` and add dependency on git4idea plugin.
<depends>Git4Idea</depends>
See https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html
Thanks. It worked.
Please sign in to leave a comment.
To get current branch name:
To get all commits in a local branch (query `git log <branch name>`)
Thanks for the reply.
I added the code to get branch name, and it compiled OK, but failed at testing:
Here is the code:
Here is part of build.gradle:
You need to modify your `plugin.xml` and add dependency on git4idea plugin.
See https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html
Thanks. It worked.