cypresslab/gitelephant
GitElephant is a PHP OOP wrapper around the git CLI for managing repositories: inspect commits, branches, tags, diffs, logs, and statuses, and run common git operations via a clean API. Supports git >=1.8, PHP >=7.2 (older PHP via prior versions).
exec().exec('git ...') or libraries like league/git, GitElephant offers a more PHP-native API with built-in error handling and edge-case management.GitElephant\GitElephant class to Laravel’s container.GitElephant::commit()).php-gd (for image diffs, optional).GitElephant\Repository\RepositoryInterface).GitElephant::validateRepository($path)).diff(), log()) may block execution. Not async by default..git directory) could expose sensitive data if misconfigured.exec('git ...') be a fallback for unsupported operations?GitElephant as a singleton or context-bound service.php artisan git:pull).git:commit:created).composer require cypresslab/gitelephant.exec('git ...') call in a Laravel command/controller with GitElephant.// Before
exec('git checkout main', $output);
// After
$git = app(GitElephant::class);
$git->checkout('main');
GitService facade wrapping GitElephant methods.namespace App\Services;
class GitService {
public function __construct(private GitElephant $git) {}
public function safeCommit(string $message, string $repoPath) {
try {
$this->git->addAll($repoPath);
$this->git->commit($message, $repoPath);
return true;
} catch (\Exception $e) {
Log::error("Git commit failed: {$e->getMessage()}");
return false;
}
}
}
.env..git directory must be accessible./ vs. \) should be normalized.config/services.php.'git' => [
'repos' => [
'default' => storage_path('app/git/repo'),
],
],
commit(), pull()).GitException). Log these centrally.GitElephant::getLastError() for debugging.../ or absolute paths).git:fetch).git:commit).Storage::lock()) or database semaphores.if (Storage::lock('git-repo-' . $repoPath)) {
$git->commit($message, $repoPath);
Storage::releaseLock('git-repo-' . $repoPath);
}
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Corrupt Git repo | App crashes or silent failures | Validate repo health on startup. |
Permission denied on .git |
Operations fail | Use Laravel’s filesystem permissions. |
Disk full during git:clone |
Clone fails | Monitor disk space; use S3 for large repos. |
| Network timeout (remote repos) | git:pull/git:push hangs |
Set timeouts; retry with exponential backoff. |
| Laravel process killed mid-operation | Partial commits/detached HEAD | Use transactions or rollback scripts. |
How can I help you explore Laravel packages today?