Example #1
0
File: test.php Project: git4p/git4p
$c = new GitCommit($git);
$c->setTree($t->sha())->addParent($oc->sha())->setMessage('Update readme.')->addAuthor($author)->addCommiter($committer)->store();
echo "Created {$c}\n";
$p = $c->sha();
// Add a commit to develop
$b = new GitBlob($git);
$b->setData("Altered README.MD file!\n")->store();
echo "Created {$b}\n";
$arr = ['README.md' => $b];
$t = new GitTree($git);
$t->setData($arr)->store();
echo "Created {$t}\n";
$author->setTimestamp('1374158776');
$committer->setTimestamp('1374158776');
$c = new GitCommit($git);
$c->setTree($t->sha())->addParent($p)->setMessage('Correct readme.')->addAuthor($author)->addCommiter($committer)->store();
echo "Created {$c}\n";
$author->setTimestamp('1384158776');
$committer->setTimestamp('1384158776');
$sc = new GitCommit($git);
$sc->setTree($t->sha())->addParent($firstcommit)->addParent($c->sha())->setMessage('Merge develop into master.')->addAuthor($author)->addCommiter($committer)->store();
echo "Created {$sc}\n";
// Update develop branch's pointer
$git->updateBranch('develop', $c->sha());
$git->updateBranch('master', $sc->sha());
$tagger->setTimestamp('1374058776');
$tag = new GitTag($git);
$tag->setObject($oc)->setTag('v0.1')->setTagger($tagger)->setMessage('Tagging the first commit...')->store();
echo "Created {$tag}\n";
// Create the tag's reference
Git::writeFile($dir . '/refs/tags/' . $tag->tag(), '' . $tag->sha() . "\n");
Example #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());