Beispiel #1
0
use Git4p\GitTree;
use Git4p\GitUser;
// Test setup
$readme = "GIT4P\n=====\n\nThis is a simple test repo for git4p.\n";
$dir = dirname(__FILE__) . '/mytestrepo';
$git = false;
$author = new GitUser();
$author->setName('Martijn')->setEmail('*****@*****.**')->setTimestamp('1374058686')->setOffset('+0200');
$committer = new GitUser();
$committer->setName('Martijn')->setEmail('*****@*****.**')->setTimestamp('1374058686')->setOffset('+0200');
$tagger = new GitUser();
$tagger->setName('Martijn')->setEmail('*****@*****.**')->setTimestamp('1374058686')->setOffset('+0200');
// Create the repo if necessary or just a reference to existing repo
if (file_exists($dir . '/HEAD') === false) {
    echo "Repo does not exist, creating on disk.\n";
    $git = Git::init($dir);
} else {
    echo "Repo exists, creating reference object instance.\n";
    $git = new Git($dir);
}
// Create a basic one file initial commit, then simulate a push to the repo
echo "Simulate that a README file was commited and pushed to master.\n";
$b = new GitBlob($git);
$b->setData($readme)->store();
echo "Created {$b}\n";
$arr = ['README.md' => $b];
$t = new GitTree($git);
$t->setData($arr)->store();
echo "Created {$t}\n";
$c = new GitCommit($git);
$c->setTree($t->sha())->setMessage('Initial commit.')->addAuthor($author)->addCommiter($committer)->store();
Beispiel #2
0
 * Copyright (c) 2015 Martijn van der Kleijn <*****@*****.**>
 * Licensed under the MIT license <http://opensource.org/licenses/MIT>
 */
/* EXAMPLE FROM README */
/*
 * How to use this example:
 *
 * - install php-cli if needed
 * - run it: php <filename>
 * - check the result using instaweb
 *   cd /tmp/mytestrepo
 *   git instaweb
 */
include '../src/git4p.php';
use Git4p\Git;
use Git4p\GitBlob;
use Git4p\GitCommit;
use Git4p\GitTree;
use Git4p\GitUser;
$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('*****@*****.**')->setTimestamp('1374058686')->setOffset('+0200');
$b = new GitBlob($git);
$b->setData($readme)->store();
$arr = ['README.md' => $b];
$t = new GitTree($git);
$t->setData($arr)->store();
$c = new GitCommit($git);
$c->setTree($t->sha())->setMessage('Initial commit.')->addAuthor($user)->addCommiter($user)->store();
$git->updateBranch('master', $c->sha());