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.
Installation:
composer require emtiazzahid/git-log-laravel
Add the service provider to config/app.php:
Emtiazzahid\GitLogLaravel\GitLogServiceProvider::class,
Route Setup:
Add a route in routes/web.php:
Route::get('git-log', '\EmtiazZahid\GitLogLaravel\GitLogLaravelController@index')->name('git-log');
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.
\EmtiazZahid\GitLogLaravel\GitLogLaravelController – Handles the logic for fetching and displaying Git logs.\EmtiazZahid\GitLogLaravel\GitLogServiceProvider – Registers bindings and routes (if published).php artisan vendor:publish --provider="Emtiazzahid\GitLogLaravel\GitLogServiceProvider" to customize behavior (e.g., log file paths, branch filtering).Basic Integration:
/git-log) for a quick overview of commit history.Route::get('custom-git-log', '\EmtiazZahid\GitLogLaravel\GitLogLaravelController@index')->name('custom.git-log');
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
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
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');
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).
Debugging Git Issues: Use the Git log viewer to inspect commit history during deployments or when reverting changes. Example workflow:
/git-log to identify recent changes.git show <hash> in the terminal.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");
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
Laravel Mix/Webpack: If extending the UI, ensure your custom CSS/JS is compiled and linked in the overridden Blade template.
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
}
}
Testing:
Mock the GitLogService in unit tests to avoid relying on the actual Git repository:
$this->app->instance(GitLogService::class, Mockery::mock(GitLogService::class));
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.
bootstrap/app.php or a service provider:
if (!\Shell::exec('git --version')) {
throw new \RuntimeException('Git is not installed or not in PATH.');
}
Permission Issues:
Laravel may not have permission to read .git logs if the storage directory lacks access.
www-data) has read access to the project’s .git directory:
chmod -R a+rX .git
Log Rotation Conflicts:
If using log rotation (e.g., laravel-log-rotate), the package may not detect rotated logs by default.
'log_path' to the correct directory or use 'log_rotate' => true if supported.Branch-Specific Logs: The package defaults to the current branch. If you switch branches, the logs may not update automatically.
$commits = $gitLogService->getCommits(10, 'feature-branch');
Large Repositories: Fetching logs for large repositories (e.g., >10,000 commits) may time out or return incomplete data.
--depth in Git commands (if supported by the package).Enable Debug Mode:
Publish the config and set 'debug' => true to log raw Git commands and output:
'debug' => env('APP_DEBUG', false),
Check Raw Output: Inspect the raw Git command output by adding a temporary log in the controller:
\Log::debug('Git command output:', $gitLogService->getRawOutput());
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
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',
],
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')]);
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();
});
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();
});
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());
}
Webhook Triggers: Use the package to log Git webhook events (e.g., push events)
How can I help you explore Laravel packages today?