PHP code example of dmamontov / git4p

1. Go to this page and download the library: Download dmamontov/git4p 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/ */

    

dmamontov / git4p example snippets


Git::init('/tmp/mytestrepo');

$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();

$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('[email protected]')
     ->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());