In Sweden we have a saying: One time is no time, two times is a habit. We’re hugely excited say that by that reckoning, we now have an open source habit at E-butik.se! Over the last months some of us here have been hinting at a cool new library we’ve been working on from time to time. The time has finally come to unveil it to the world! Gittern is a PHP library for reading from and writing to Git repositories. Without using the git binary.
We’ve got support for many things common in Git repositories. There’s your blobs, trees and commits of course, which can be stored as loose objects or in packfiles. We eat packed refs for breakfast. We also have support for using the Git index, which is a real treat if you’d like to make changes to a repo over multiple HTTP requests.
Now, it wouldn’t be much like music for PHP’s ears if the code wasn’t good, and if we’re allowed to say so ourselves, the code is pretty dang good. The code is nicely decoupled and dependency injected, which means that if you’d like to you can switch out a lot of our implementations for your own. Perhaps you’d like to cache your Git objects in Redis? Go ahead. Separate indexes for separate branches? Very much doable (indeed, we’re doing it internally).
As if all of this wasn’t enough, we’ve sweetened the pot just a little bit more. You know Gaufrette, the awesome filesystem abstraction library from the fine folks at KnpLabs? We’ve got adapters for it. That means super-easy access to Git as if it’s just another kind of filesystem!
We know that we’re not first into the field with this one. Similar libraries exist for other languages (like grit for Ruby, and dulwich for Python), and indeed for PHP too, but we’d like to think that our dependency injected and decoupled approach brings something new at least to the PHP table.
Gittern is licensed under the MIT License, and the code is available at GitHub: e-butik / Gittern. To install, however, we’d recommend using Composer, since that’ll handle all of your dependencies. Gittern is available at Packagist as e-butik/gittern.
By the way, if you think that stuff like this is cool, we’d like to remind you that we get paid for working on stuff just like this. If getting paid to work on cool things like this sounds interesting to you, you should definitely shoot us an e-mail.
— Developer blog