tjvb / githash
Get the current git hash from your project.
Requires
- php: ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
Requires (Dev)
- fakerphp/faker: ^1.15
- infection/infection: ^0.26.10 || ^0.27.0|| ^0.28.0 || ^0.29.0
- mikey179/vfsstream: ^1.6.7
- phpmd/phpmd: ^2.10
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.5 || ^10.0 || ^11.0
- slevomat/coding-standard: ^8.14
- squizlabs/php_codesniffer: ^3.7
- symfony/process: ^5.3
- symplify/easy-coding-standard: ^12.0
Suggests
- symfony/process: Used rather than `shell_exec` if available (tested with ^5.3).
README
This package is intended to give a useful option for getting the hash from the current commit.
Usage
try {
$retriever = Retriever::getWithFactory(GitHashFinderFactory::withDefaultFinders());
echo $retriever->getHash($path)->hash() . PHP_EOL;
} catch (GitHashException $exception) {
echo 'Failed to get the hash ' . $exception->getMessage() . PHP_EOL;
}
Examples
See docs/examples for examples about how to use this package.
Installation
You can install this package with composer by executing the command: composer require tjvb/githash
.
Different HashFinders
The package provide 3 different GitHashFinder they all have some pro's and con's.
GitHashFinder | Requirements | Benefits | Cons |
---|---|---|---|
GitProcessCommandHashFinder | The symfony/process package and git executable. | This execute the git commands with the symfony/process package to get good feedback. | You need to install this package and have the git command available. |
GitShellExecCommandHashFinder | The shell_exec PHP function and git executable. | This execute the git commands. | You need to have shell_exec and the git command available. |
GitFileSystemHashFinder | A branch. | It reads the git files and doesn't need to have a git executable. | The repository need to have a branch, it doesn't work with a detached head. |
Laravel package
If you use Laravel you can use tjvb/laravel-githash, this package can add the hash to your log files and provides a blade component to show the hash.
Changelog
We (try to) document all the changes in CHANGELOG so read it for more information.
Contributing
You are welcome to contribute, read about it in CONTRIBUTING
License
The MIT License (MIT). Please see License File for more information.