(Plugin development - open api) how to detect merge conflicts using git4idea?

Answered

Hello. I'm new to plugin development for IntelliJ and I'm trying to create a plugin dealing with git (using git4idea). I want my plugin to detect merge conflicts (whether the user used IntelliJ actions to merge or through the terminal like running the git merge command). I plan to display some information once a conflict has been found. Any advice on how to do this?

0
3 comments

You should check the GitStagingAreaHolder class. There is a StagingAreaListener listener available, which is invoked by the refresh method so you can track the changes in the repositories.

Having the GitRepository object available, you can fetch a loop through all conflicts:

repository.getStagingAreaHolder().getAllConflicts()
0

Hi there,

Thanks for your help. Apparently, the class GitStagingAreaHolder does not exist with my current version of IntelliJ Idea (CE 2020.1.2), however, I discovered:

repository.getConflictsHolder().getConflicts()

I'm assuming they're similar? Also, to clarify, would I need to make use of :

project.getMessageBus().connect().subscribe(GitConflictsHolder.CONFLICTS_CHANGE, new GitConflictsHolder.ConflictsLisetener() {

@Override
public void conflictsChanged(@NotNull GitRepository repository) {
// some code here
}
});

I'm not sure if GitConflictsHolder is what I need exactly, so I just wanted to make sure and ask here.

Thanks in advance!

0

Also, just another question to add to this: how can I determine the branches involved in the merge conflict?

0

Please sign in to leave a comment.