Iterate over only git tracked files

Answered

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? It would really help a lot!
 

0
4 comments

Hi Ramon,

Please try using com.intellij.openapi.vcs.changes.ChangeListManager#getAllChanges.

0

Hi Karol Lewandowski ,

Thanks for the quick suggestion!

Looking at the naming (I might be wrong) I suspect this class and method to be handling changes since the last git commit? What I need is to basically iterate over all files that are tracked by git for the whole repository. To give some more background, I want to offer the end-user a fuzzy search extension for ideavim. In this extension it is already possible to do a fuzzy search over all files within the project (via ProjectFileIndex), however I want to add a new feature so that people can enable to only search over git tracked files.

Greetings,

Ramon

0

Hi Ramon,

You are right. This method doesn't do what you meant. Sorry for the confusion.

Could you please try isUnversioned and isIgnoredFile from the same class?

0

Thanks Karol Lewandowski ,

In combination with the loop over ProjectFileIndex this worked pretty well, e.g. continuing in the loop if isIgnoredFile returns true.

 

0

Please sign in to leave a comment.