- What is graham-campbell/git-wrapper and how does it work?
- It is a thin, object-oriented PHP wrapper around the Git command-line client. Every call shells out to the git binary through symfony/process and returns structured output and exit codes. It adds no Git capability of its own, so every operation depends on the installed binary and the state of a working copy on disk. Treat it as a process-execution adapter, not a Git implementation.
- How do I install graham-campbell/git-wrapper with Composer?
- Run composer require graham-campbell/git-wrapper and pin a version such as ^1.1. Check that the dependency constraints resolve against your exact PHP and Laravel versions before doing any design work. There is no service provider, so installation is just the library plus the wiring you write yourself.
- Is graham-campbell/git-wrapper a Laravel package with a service provider and facade?
- No. The current line is framework-agnostic and ships no service provider, facade, or publishable config. Laravel integration is roughly 10 to 50 lines in AppServiceProvider: instantiate the wrapper and bind a configured singleton. An earlier release may have offered Laravel glue, so confirm the behaviour on the version you actually install.
- Which Laravel and PHP versions does graham-campbell/git-wrapper support?
- The package targets modern PHP 8.x, but older 1.x releases may carry Laravel 4.2 or 5.x-era constraints. Run a quick go/no-go Composer resolve in a throwaway app against your exact Laravel and PHP pair before committing to a design. If it does not resolve, depend on the underlying library directly and register your own binding.
- How do I clone a repository or run a Git command with this wrapper?
- Instantiate the wrapper against a working copy and call the object-oriented methods for clone, checkout, commit, log, and describe. Each call returns the process output and exit code and throws GitException on failure. For anything not covered by a dedicated method, you can run arbitrary git subcommands through the same process adapter.
- How do I configure the Git binary path, timeout, or environment variables?
- Configure the wrapper with an explicit binary path, an explicit timeout, and a logger when you bind it as a singleton. This keeps behaviour predictable on hosts where git lives in a non-standard location. Custom environments can also be passed through to the Symfony Process call for things like SSH agent or credential settings.
- How does graham-campbell/git-wrapper handle errors?
- Failed commands throw a GitException carrying the process output and exit code so you can catch and log them. There is no retry or async handling built in, since each call is a synchronous fork and exec. Always set a timeout and wrap calls in try/catch so a hung git process cannot stall your worker.
- Is it safe to pass user input into Git commands with this wrapper?
- The library escapes arguments, but branch names, refs, remote URLs, paths, and commit messages derived from external input remain injection candidates. Validate and allowlist those values yourself and always run git against a sandboxed working directory. Read GitCommand::__toString() in your pinned version to verify the escaping rather than assuming it.
- Can I run Git commands inside a Laravel web request with this package?
- You can, but you should not. Every call is a fork and exec that needs a writable working copy, credentials, and the git binary, and it fails behind disable_functions, open_basedir, or read-only filesystems. Move Git work into a queued job with a timeout and a capped output buffer instead of running it inline on the request path.
- What are the alternatives to graham-campbell/git-wrapper and is it still maintained?
- Alternatives include shelling out to git yourself, depending on the underlying library directly, or using a heavier Git implementation. This is a small MIT utility with a single maintainer and no dependents, so the integration glue is yours to own regardless of upstream activity. Budget for tracking git advisories like CVE-2024-32002 yourself, because Composer audit will not surface them.