Search code examples
gitlibgit2objective-git

Can I have an in-memory git repository for unit-testing with libgit2 / ObjectiveGit?


I work on an Objective-C, Cocoa project with libgit2 and it's ObjectiveGit bindings.

In order to set up fast and clean unit tests, it would be nice to have an in-memory repository. Is this possible?


Solution

  • You can use git_repository_new() to create the object itself without any references to on-disk resources. You can then put in your own object db, reference db, configuration and workdir path.

    But writing your own databases for everything would likely be more work than abstracting away your uses of libgit2 if you don't really want to use it for the tests.