javakotlinintellij-ideaintellij-pluginideavim

IntelliJ plugin development - loop over only git tracked files


Currently I am working on an IntelliJ plugin, with this plugin I want to iterate over a list of files that are only tracked by git (so excluding the files in the .gitignores).

I am able to loop over files via ProjectFileIndex, then I use the iterateContent method with a ContentIterator. This works fine for all project files, however I was wondering if there is a way to do this with only git tracked files. I already looked into the APIs of git4idea but I couldn't find any class which provides this functionality. I am completely new to Kotlin and IntelliJ plugin development in general.

Are there any recommendations on how to do this properly?


Solution

  • Eventually I used the isIgnoredFile(file: VirtualFile) function in the com.intellij.openapi.vcs.changes.ChangeListManager class in combination with the ProjectFileIndex that I was already using.

    The ProjectFileIndex instance has a method iterateContent where you can define your own ContentIterator, within this ContentIteraror you can use the isIgnoredFile method from the ChangeListManager instance to filter out the VCS ignored files.