Search code examples
gitlibgit2

libgit2 how to get the the status of the current directory?


How can I get the status of a single directory, rather than the whole repository?

I have looked at the following:

  • git_status_list_new which gets the repository status, but I care only about files located in a single directory.

  • git_status_file which gets the status of a single.

Is there a way that I can get the status of a single directory using libgit2?


Solution

  • git_status_list_new accepts a git_status_options struct, which contains a pathspec member which controls which files will be included in the list. You can use that to limit your returned statuses to those in a single directory.