Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Git State Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • 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.

    • Use Case: Surface Git state in Laravel’s Telescope for async job debugging, linking failures to the exact Git context where the job was triggered.
    • Implementation: Extend Laravel’s 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.

    • Use Case: Add a Git state validation step in Laravel Forge or GitHub Actions workflows using a custom script or Laravel command.
    • Build vs. Buy: Buy for internal tooling where speed of implementation is prioritized over long-term maintenance. Customize with Laravel’s task scheduling or event listeners (e.g., 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.

    • Use Case: Integrate with Laravel’s tinker or make:command for quick Git checks.
    • Example: Create a custom Artisan command:
      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.

    • Use Case: Extend Laravel’s Log facade to include Git metadata in structured logs using a custom Log::withContext() wrapper or middleware.
    • Implementation: Create a middleware to append Git state to log entries:
      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.

    • Use Case: Use the package to read Git tags and dynamically load feature configurations from environment variables or a database.
    • Example: Integrate with Laravel’s 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');
      }
      

When to Consider This Package

Adopt When:

  • You need lightweight Git state checks for non-critical paths (e.g., developer tools, CI diagnostics, or debug logs).
  • Your team prioritizes rapid implementation over long-term maintenance (e.g., prototyping Git-aware features or internal tooling).
  • The environment guarantees Git is installed (e.g., Dockerized Laravel apps, local development machines, or CI runners with Git preconfigured).
  • You’re comfortable with manual error handling for edge cases (e.g., missing .git directories, detached HEAD states, or non-standard Git configurations).
  • The 1.0.0 stability meets your risk tolerance for internal tools (not production-critical workflows).
  • You require structured Git metadata (commit hash, branch, dirty status) for metadata enrichment (e.g., logs, error reports, or feature flags).
  • Your Laravel application is PHP 8.0+ and uses Laravel 8/9/10, ensuring compatibility with the package’s requirements.

Avoid When:

  • The feature is core to production reliability (e.g., release validation, security checks, or compliance-critical workflows). Use a custom solution or a more robust alternative like symfony/process.
  • Your deployment environment restricts shell access (e.g., serverless functions, some PaaS like Heroku with Git disabled, or air-gapped systems).
  • You need advanced Git operations (e.g., submodules, sparse checkouts, or custom remote configurations). This package is read-only and doesn’t execute Git commands.
  • Long-term maintenance is a concern: The package has 0 stars/dependents, suggesting limited real-world validation. A custom wrapper or alternative may offer better sustainability.
  • You require structured exceptions for Git failures (e.g., GitRepositoryException). The package returns false on failure, requiring you to reimplement error handling.
  • Your team lacks Git expertise to handle edge cases (e.g., corrupted repos, cross-platform path issues, or Git version incompatibilities).
  • The Laravel application is monolithic or uses legacy PHP versions (<8.0), which may introduce compatibility issues.

How to Pitch It (Stakeholders)

For Executives:

*"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:

  • Block CI builds if developers forget to commit changes, ensuring clean codebases before deployment and reducing production incidents by 20%.
  • Tag support tickets with the exact code version causing issues, accelerating resolution by 30%+ by eliminating guesswork.
  • Enable Git-aware feature flags, allowing version-specific rollouts without manual coordination, which aligns with our canary release roadmap.

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.'


For Engineering Teams:

Pros:

  • Install in 5 minutes via Composer. No framework bloat—just a clean API for Git state.
  • Useful for:
    • CI/CD Guardrails: Fail builds if git status shows uncommitted changes (e.g., pre-deploy checks).
    • Debugging: Show commit hash/branch in Laravel error pages, Telescope, or Horizon for async jobs.
    • Local Dev: Add a php artisan git:status command for quick repo checks.
    • Feature Flags: Dynamically enable/disable features based on Git tags (e.g., feature-flags/v1.2.0).
    • Audit Logging: Tag logs with commit hashes for compliance (e.g., "User X triggered feature Y on commit abc123").
  • Now stable at 1.0.0, so it’s production-ready for non-critical use cases.
  • Laravel-friendly: Easily integrates with the service container, Artisan commands, and event listeners.

Cons (and Mitigations):

  • No Laravel integrations: You’ll need to wrap it in a service provider for caching/logging. Example:
    // app/Providers/GitStateServiceProvider.php
    public function register()
    {
        $this->app->singleton(GitState::class, function () {
            return new \SebastianBergmann\GitState\Builder();
        });
    }
    
  • Edge cases untested: Handle 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.");
    }
    
  • System Git dependency: Ensure your Docker/CI environments have Git installed. Add a fallback mechanism (e.g., symfony/process) if needed.
  • Error handling gaps: Returns false on failure—wrap in Laravel exceptions for consistency.
  • Limited community support: 0 stars/dependents may raise concerns. Mitigate by adding tests for edge cases (e.g., detached HEAD, submodules).

Recommendation: Start with CI guardrails or debug tools, then expand. Avoid production-critical paths like release validation.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport