A native PHP git library
- php: ^7.4
- apigen/apigen: v4.1.1
- codacy/coverage: dev-master
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: ^4.6
This package is auto-updated.
Last update: 2023-03-27 14:58:42 UTC
Status: No longer active / archived
"Git4P" stands for "Git for PHP" and is a native PHP Git library that can access a Git repository without using external help like the standard git commands. It is geared towards server side (bare) repositories.
Please let me know how you're using this library.
Create a new bare repository
Add a simple blob
In this example the blob is 'orphaned', which means it is unreachable through any commits.
$git = Git::init('/tmp/mytestrepo'); $readme = "GIT4P\n=====\n\nThis is a simple test repo for git4p.\n"; $blob = new GitBlob($git); $blob->setData($readme) ->store();
Full basic repository with a single commit
We programmatically create a blob (file), a tree (directory) that points to it
and then a commit pointing to the tree. Finally we make sure the
points to this commit.
$git = Git::init('/tmp/mytestrepo'); $readme = "GIT4P\n=====\n\nThis is a simple test repo for git4p.\n"; $user = new GitUser(); $user->setName('Some User') ->setEmail('firstname.lastname@example.org') ->setTimestamp('1374058686') ->setOffset('+0200'); $blob = new GitBlob($git); $blob->setData($readme) ->store(); $arr = ['README.md' => $b]; $tree = new GitTree($git); $tree->setData($arr) ->store(); $commit = new GitCommit($git); $commit->setTree($tree->sha()) ->setMessage('Initial commit.') ->addAuthor($user) ->addCommiter($user) ->store(); $git->updateBranch('master', $commit->sha());
This library currently has limited pack support. Reading in and listing packed refs is supported through GitRef but support for packed objects is not implemented yet.
- Add pack support
- Add proper phpdoc blocks