1. Go to this page and download the library: Download igorsgm/laravel-git-hooks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// App/Console/GitHooks/MyPreCommitHook.php
namespace App\Console\GitHooks;
use Closure;
use Igorsgm\GitHooks\Git\ChangedFiles;
class MyPreCommitHook implements \Igorsgm\GitHooks\Contracts\PreCommitHook
{
// ...
public function handle(ChangedFiles $files, Closure $next)
{
// TODO: Implement your pre commit hook logic here.
// If you want to cancel the commit, you have to throw an exception.
// i.e: throw new HookFailException();
// Run the next hook in the chain
return $next($files);
}
}
// App/Console/GitHooks/MyPrepareCommitMessageHook.php
namespace App\Console\GitHooks;
use Closure;
use Igorsgm\GitHooks\Git\CommitMessage;
use Igorsgm\GitHooks\Contracts\MessageHook;
class MyPrepareCommitMessageHook implements \Igorsgm\GitHooks\Contracts\MessageHook
{
// ...
public function handle(CommitMessage $message, Closure $next)
{
// TODO: Implement your prepare commit msg hook logic here.
$currentMessage = $message->getMessage();
// You can update commit message text
$message->setMessage(str_replace('issue', 'fixed', $currentMessage));
// If you want to cancel the commit, you have to throw an exception.
// i.e: throw new HookFailException();
// Run the next hook in the chain
return $next($message);
}
}
// App/Console/GitHooks/MyPrepareCommitMessageHook.php
namespace App\Console\GitHooks;
use Closure;
use Igorsgm\GitHooks\Git\CommitMessage;
use Igorsgm\GitHooks\Contracts\PostCommitHook;
class MyPostCommitHook implements \Igorsgm\GitHooks\Contracts\PostCommitHook
{
// ...
public function handle(Log $log, Closure $next)
{
// TODO: Implement post commit hook logic here.
// You can interact with the commit log
$hash = $log->getHash();
$author = $log->getAuthor();
$date = $log->getDate();
$message = $log->getMessage();
// If you want to cancel the commit, you have to throw an exception.
// i.e: throw new HookFailException();
// Run the next hook in the chain
return $next($log);
}
}