PHP git wrapper
Fund package maintenance!
sebastianfeldmann
Installs: 3 759 539
Dependents: 13
Suggesters: 0
Security: 0
Stars: 46
Watchers: 2
Forks: 12
Open Issues: 2
Requires
- php: >=8.0
- ext-json: *
- ext-libxml: *
- ext-simplexml: *
- sebastianfeldmann/cli: ^3.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- dev-main
- 3.11.1
- 3.11.0
- 3.10.0
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.8.9
- 3.8.8
- 3.8.7
- 3.8.6
- 3.8.5
- 3.8.4
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.0
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- 2.4.0
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.1
- 2.0.0
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-detect-squash-and-fixup-commits
This package is auto-updated.
Last update: 2024-11-27 18:50:28 UTC
README
This lib is used to execute git
commands directly from PHP via a defined api.
All you have to do is setup a Repository
object, retrieve a command Operator
and fire away. Each git command like git config or git log is handled
by a separate Operator
. Follow the next steps to give it a try.
Installation
The git package is installable via composer. Just run the following command.
$ composer require sebastianfeldmann/git
Usage
Setup the Repository
$repoRootPath = '/var/www/my-project'; $gitRepository = new Git\Repository($repoRootPath);
Retrieve the needed Operator
$log = $gitRepository->getLogOperator();
Get files and commits since some tag
$files = $log->getChangedFilesSince('1.0.0'); $commits = $log->getCommitsSince('1.0.0');
Copy Paste Example
use SebastianFeldmann\Git; require __DIR__ . '/../vendor/autoload.php'; // path to repository without .git $repoRootPath = '/path/to/repo'; $gitRepository = new Git\Repository($repoRootPath); // get files and commits since hash or tag $log = $gitRepository->getLogOperator(); $files = $log->getChangedFilesSince('1.0.0'); $commits = $log->getCommitsSince('1.0.0'); // check the index status $index = $gitRepository->getIndexOperator(); $files = $index->getStagedFiles();
Available operators
- Config - Access all git settings e.g. line break settings.
- Diff - Compare two versions.
- Index - Check the staging area.
- Info - Access the current state like branch name or commit hash.
- Log - Returns list of changed files and other git log information.
Example commands
Get the current tag:
// git describe --tag
$tag = $infoOperator->getCurrentTag();
Get tags for a given commit:
// git tag --points-at HEAD
$tags = $infoOperator->getTagsPointingTo('HEAD');
Get the current branch:
// git rev-parse --abbrev-ref HEAD
$branch = $infoOperator->getCurrentBranch();
Get a list of staged files:
// git diff-index --cached --name-status HEAD
$files = $indexOperator->getStagedFiles();
Get all current git settings:
// git config --list
$config = $configOperator->getSettings();
Get all changed files since a given commit or tag:
// git log --format='' --name-only $HASH
$files = $logOperator->changedFilesSince('1.0.0');
Get differences between two versions
// git diff '1.0.0' '1.1.0'
$changes = $diffOperator->compare('1.0.0', '1.1.0');