sebastian/git-state
Describe the state of a Git checkout from PHP. Detect origin URL, current branch and commit hash, and whether the working directory is clean; otherwise return the git status output. Useful for build metadata and diagnostics.
Enhanced Debugging & Observability: Integrate Git metadata (commit hash, branch, dirty status) into Laravel’s error reporting (e.g., Sentry, Telescope, or custom dashboards) to improve traceability. This aligns with the "Improved Debugging Tools" initiative, reducing Mean Time to Resolution (MTTR) for production issues by auto-tagging exceptions with Git context.
App\Exceptions\Handler to include Git state in error payloads via a custom render() method or report() callback.CI/CD Guardrails & Reproducibility: Implement pre-deployment checks to fail builds if the working directory is dirty, ensuring clean codebases before merges or deployments. This supports the "Automated Release Validation" roadmap by enforcing Git best practices.
Deploying event).Developer Experience (DX) Improvements:
Add a php artisan git:status command to display branch/commit info without leaving the terminal, reducing context-switching. This accelerates local development workflows by surfacing Git state in Laravel’s CLI.
tinker or make:command for quick Git checks.php artisan make:command GitStatusCommand
Audit Logging & Compliance:
Tag logs with commit hashes for compliance tracking (e.g., "User X triggered feature Y on commit abc123"). This is critical for regulated industries (e.g., finance, healthcare) where traceability is mandatory.
Log facade to include Git metadata in structured logs using a custom Log::withContext() wrapper or middleware.public function handle($request, Closure $next)
{
$gitState = (new \SebastianBergmann\GitState\Builder)->build();
Log::withContext(['git' => $gitState])->info('User action triggered');
return $next($request);
}
Dynamic Feature Flags:
Enable/disable features based on Git tags (e.g., feature-flags/v1.2.0), allowing for version-specific rollouts. This supports the "Canary Releases" roadmap by enabling Git-aware feature toggles.
spatie/laravel-feature-flags package to enable features based on Git state:
$gitState = (new \SebastianBergmann\GitState\Builder)->build();
if ($gitState->branch() === 'feature/flags-v2') {
Feature::enable('new_ui');
}
.git directories, detached HEAD states, or non-standard Git configurations).symfony/process.GitRepositoryException). The package returns false on failure, requiring you to reimplement error handling.*"This package enables us to automate Git state checks in Laravel, reducing debugging time and improving release reliability. By embedding commit hashes, branch names, and dirty status into logs and error screens, we can:
It’s now stable at 1.0.0, so the risk is low for internal tools. The payoff? Faster releases, fewer ‘works on my machine’ bugs, and happier engineers who don’t have to manually check Git status.
Key Ask: 'Approve a 2-week pilot to integrate this into our CI/CD guardrails and debug tools. If successful, we’ll expand to feature flags and audit logging—delivering measurable improvements in developer productivity and release quality. Budget: $0 (open-source), ROI: Reduced MTTR and fewer production incidents.'
Pros:
git status shows uncommitted changes (e.g., pre-deploy checks).php artisan git:status command for quick repo checks.feature-flags/v1.2.0).abc123").Cons (and Mitigations):
// app/Providers/GitStateServiceProvider.php
public function register()
{
$this->app->singleton(GitState::class, function () {
return new \SebastianBergmann\GitState\Builder();
});
}
false returns manually (e.g., missing .git dirs) or extend the package with custom exceptions.
if (!$state) {
throw new \RuntimeException("Git repository not found or missing origin.");
}
symfony/process) if needed.false on failure—wrap in Laravel exceptions for consistency.Recommendation: Start with CI guardrails or debug tools, then expand. Avoid production-critical paths like release validation.
How can I help you explore Laravel packages today?