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 Log Laravel Laravel Package

emtiazzahid/git-log-laravel

View your app’s Git commit history in a simple Laravel web page. Install via Composer, register the service provider, and add a route to GitLogLaravelController. No public assets or vendor routes; supports Laravel 5–9. Optional view publish for customization.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require emtiazzahid/git-log-laravel
    

    Add the service provider to config/app.php:

    Emtiazzahid\GitLogLaravel\GitLogServiceProvider::class,
    
  2. Route Setup: Add a route in routes/web.php:

    Route::get('git-log', '\EmtiazZahid\GitLogLaravel\GitLogLaravelController@index')->name('git-log');
    
  3. First Use Case: Visit /git-log to view the Git log of your Laravel project. The package provides a simple, pre-built UI to inspect commit history, authors, dates, and commit messages.


Where to Look First

  • Controller: \EmtiazZahid\GitLogLaravel\GitLogLaravelController – Handles the logic for fetching and displaying Git logs.
  • Service Provider: \EmtiazZahid\GitLogLaravel\GitLogServiceProvider – Registers bindings and routes (if published).
  • Published Config: Run php artisan vendor:publish --provider="Emtiazzahid\GitLogLaravel\GitLogServiceProvider" to customize behavior (e.g., log file paths, branch filtering).

Implementation Patterns

Usage Patterns

  1. Basic Integration:

    • Use the default route (/git-log) for a quick overview of commit history.
    • Customize the route name or path as needed:
      Route::get('custom-git-log', '\EmtiazZahid\GitLogLaravel\GitLogLaravelController@index')->name('custom.git-log');
      
  2. Customizing Log Paths: Publish the config and modify config/git-log.php to specify custom log paths or branches:

    'log_path' => storage_path('logs/custom-git-logs'),
    'branch' => 'main', // Default branch to display
    
  3. Programmatic Access: Use the underlying service to fetch Git logs programmatically (e.g., in a command or service):

    use Emtiazzahid\GitLogLaravel\Services\GitLogService;
    
    $gitLogService = app(GitLogService::class);
    $commits = $gitLogService->getCommits(10); // Fetch last 10 commits
    
  4. Middleware or Authorization: Restrict access to the Git log route using Laravel middleware:

    Route::get('git-log', '\EmtiazZahid\GitLogLaravel\GitLogLaravelController@index')
         ->middleware('auth')
         ->name('git-log');
    
  5. Extending the UI: Override the default Blade view (resources/views/vendor/git-log-laravel/index.blade.php) to customize the layout or add functionality (e.g., filtering, search).


Workflows

  1. Debugging Git Issues: Use the Git log viewer to inspect commit history during deployments or when reverting changes. Example workflow:

    • Deploy fails → Check /git-log to identify recent changes.
    • Compare commit hashes with git show <hash> in the terminal.
  2. Release Notes Generation: Automate the extraction of commit messages for release notes by querying the Git log service:

    $recentCommits = $gitLogService->getCommits(20, 'main');
    $releaseNotes = collect($recentCommits)->pluck('message')->implode("\n");
    
  3. CI/CD Integration: Add a step in your CI pipeline to validate Git logs (e.g., ensure no critical commits were missed):

    curl -s http://localhost/git-log | grep "ERROR" || exit 1
    

Integration Tips

  1. Laravel Mix/Webpack: If extending the UI, ensure your custom CSS/JS is compiled and linked in the overridden Blade template.

  2. Artisan Commands: Create a custom Artisan command to fetch and log Git history to a database:

    use Emtiazzahid\GitLogLaravel\Services\GitLogService;
    
    class SyncGitLogsCommand extends Command {
        protected $signature = 'git:sync-logs';
        public function handle(GitLogService $gitLogService) {
            $commits = $gitLogService->getCommits(100);
            // Save to DB or file
        }
    }
    
  3. Testing: Mock the GitLogService in unit tests to avoid relying on the actual Git repository:

    $this->app->instance(GitLogService::class, Mockery::mock(GitLogService::class));
    

Gotchas and Tips

Pitfalls

  1. Git Not Installed: The package relies on Git being installed and available in the system PATH. Test locally and in CI/CD pipelines to avoid runtime errors.

    • Fix: Add a check in bootstrap/app.php or a service provider:
      if (!\Shell::exec('git --version')) {
          throw new \RuntimeException('Git is not installed or not in PATH.');
      }
      
  2. Permission Issues: Laravel may not have permission to read .git logs if the storage directory lacks access.

    • Fix: Ensure the web server user (e.g., www-data) has read access to the project’s .git directory:
      chmod -R a+rX .git
      
  3. Log Rotation Conflicts: If using log rotation (e.g., laravel-log-rotate), the package may not detect rotated logs by default.

    • Fix: Publish the config and set 'log_path' to the correct directory or use 'log_rotate' => true if supported.
  4. Branch-Specific Logs: The package defaults to the current branch. If you switch branches, the logs may not update automatically.

    • Fix: Explicitly set the branch in the config or pass it to the service:
      $commits = $gitLogService->getCommits(10, 'feature-branch');
      
  5. Large Repositories: Fetching logs for large repositories (e.g., >10,000 commits) may time out or return incomplete data.

    • Fix: Limit the number of commits fetched or use --depth in Git commands (if supported by the package).

Debugging

  1. Enable Debug Mode: Publish the config and set 'debug' => true to log raw Git commands and output:

    'debug' => env('APP_DEBUG', false),
    
  2. Check Raw Output: Inspect the raw Git command output by adding a temporary log in the controller:

    \Log::debug('Git command output:', $gitLogService->getRawOutput());
    
  3. Verify Git Commands: Manually run the Git command used by the package to ensure it works:

    git log --pretty=format:"%h - %an, %ar : %s" -n 10
    

Config Quirks

  1. Published Config: After publishing (php artisan vendor:publish), the config file (config/git-log.php) may not auto-load. Ensure it’s included in config/app.php:

    'config' => [
        // ... other configs
        Emtiazzahid\GitLogLaravel\GitLogServiceProvider::class => __DIR__.'/git-log.php',
    ],
    
  2. Environment Variables: The package does not natively support environment variables for config values. Override the config file directly or use Laravel’s config() helper:

    config(['git-log.branch' => env('GIT_LOG_BRANCH', 'main')]);
    

Extension Points

  1. Custom Git Commands: Extend the GitLogService to support custom Git commands. Override the service binding in the service provider:

    $this->app->bind(GitLogService::class, function ($app) {
        return new CustomGitLogService();
    });
    
  2. Database Storage: Store Git logs in a database table for querying. Create a migration and update the service:

    // Example migration
    Schema::create('git_commits', function (Blueprint $table) {
        $table->id();
        $table->string('hash');
        $table->text('message');
        $table->string('author');
        $table->timestamp('date');
        $table->timestamps();
    });
    
  3. API Endpoint: Convert the controller logic into an API resource for programmatic access:

    Route::get('api/git-log', [GitLogLaravelController::class, 'apiIndex']);
    

    Update the controller to return JSON:

    public function apiIndex() {
        return response()->json($this->gitLogService->getCommits());
    }
    
  4. Webhook Triggers: Use the package to log Git webhook events (e.g., push events)

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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime