- What is gitonomy/gitlib used for in a Laravel application?
- Gitonomy Gitlib lets PHP code read Git repositories programmatically: commits, trees, branches, tags, references, diffs, and blame. In Laravel it is useful for release dashboards, deployment tooling, CI scripts, changelog generators, and admin panels that inspect repository history. It works by making shell calls to the system Git binary, so no native extension is required. The API wraps Git output in objects such as Repository, Commit, Branch, and Diff.
- How do I install gitonomy/gitlib with Composer?
- Run composer require gitonomy/gitlib from your Laravel project root. Version 1.7 requires PHP 8.1 or newer; on PHP 8.0 Composer will resolve to version 1.6 instead. The package also introduces symfony/deprecation-contracts as a dependency, so review composer.lock after upgrading. No Laravel service provider is published by the package itself, so you can register any wrapper or CliDriver configuration in your own provider.
- Which Laravel and PHP versions are supported by gitonomy/gitlib 1.7?
- Gitonomy Gitlib 1.7 requires PHP 8.1 or later, mainly because it uses the DiffLineType enum. Laravel 9 and newer on PHP 8.1+ are the recommended combination. Laravel 8 may work only if your application has been patched to run on PHP 8.1, so verify that environment before adopting 1.7. The library still depends on a system Git binary, and Windows support should be validated separately.
- How do I configure the Git binary path, timeout, and logger with CliDriver?
- Version 1.7 adds a CliDriver that lets you configure the Git binary path, environment variables, timeout, and logger. Create and configure the driver in a Laravel service provider, then pass it to the Repository or related APIs. This is useful in containers or restricted environments where Git is installed in a non-standard location or where environment variables must be controlled. Centralising this configuration also makes it easier to apply consistent timeouts and logging across Git operations.
- How do I read commits, branches, tags, and diffs using Gitlib?
- Create a Repository object with the path to your local Git repository, then use methods such as getReferences()->getBranches() and getReferences()->getTags() to list references. Commits and trees can be inspected through the Commit and Tree APIs, while diffs are available through Repository::getDiff() and FileChange::getDiffLines(). Version 1.7 also adds APIs for blame line ranges, log pagination with Log::withOffset(), tree iteration, and submodules.
- Is gitonomy/gitlib safe from command injection?
- Gitonomy Gitlib makes shell calls to Git, so command injection remains a risk if you pass untrusted user input into Git commands or arguments. The CliDriver improves control over the binary path and environment but does not remove the need to sanitise input. Avoid interpolating request data directly into command strings, validate branch names, paths, and revision ranges, and prefer passing arguments as arrays where the API supports it. Treat any user-supplied Git reference or path as untrusted.
- What deprecations should I fix before upgrading to gitonomy/gitlib 2.0?
- Version 1.7 deprecates several older APIs while keeping 1.6 behaviour working. Common replacements include moving from one-argument Repository::getDiff() to the two-argument form, replacing FileChange::getLines() with getDiffLines(), and using tree iteration instead of Tree::getEntries(). Deprecation warnings will appear in logs or static analysis when old methods are used, so address them incrementally. The package includes UPGRADE-2.0.md as migration guidance for the eventual 2.0 release.
- How do I test Gitlib code in Laravel without a real repository?
- Gitonomy Gitlib has no in-memory repository fake because it shells out to the real Git binary. The most reliable approach is to create temporary local repositories in your test setup, run real Git commands against them, and assert on the parsed results. Keep fixtures small and clean them up after each test, and make sure the test environment has a compatible Git version available. For unit tests of your own wrapper code, you can mock your application service rather than Gitlib itself.
- What are alternatives to gitonomy/gitlib for Git operations in PHP?
- If you only need to run a few Git commands, using Symfony Process directly or PHP's shell execution functions may be simpler than adding a parsing library. Gitonomy Gitlib is most valuable when you need structured access to commits, trees, diffs, blame, and references without writing your own parsers. Other Git wrapper packages exist, but evaluate their maintenance status, PHP version support, and whether they are safe for untrusted input. For Laravel projects, it is also worth considering whether a small internal GitService abstraction around your chosen approach is sufficient.
- Is gitonomy/gitlib actively maintained and when will 2.0 be released?
- Version 1.7.0 is an active release and the maintainers have added deprecations to prepare for a 2.0 release. That indicates ongoing maintenance, but the provided release information does not include a fixed 2.0 timeline. Monitor the GitHub repository, release notes, and UPGRADE-2.0.md for the latest guidance. Because the library remains niche, track issues and community discussion if you depend on it in production.