Beispiel #1
0
 private function loadRefs()
 {
     $refs = [];
     // load packed refs if any
     $packfile = $this->git->dir() . '/packed-refs';
     if (file_exists($packfile) === true) {
         $file = trim(Git::readFile($packfile));
         $line = strtok($file, "\n");
         while ($line !== false) {
             $line = trim($line);
             if ($line[0] != '#' && $line[0] != '^') {
                 if (strpos($line, ' ') == 40) {
                     $refs[substr($line, 46)] = substr($line, 0, 40);
                 }
             }
             $line = strtok("\n");
         }
         // Clean up memory
         strtok('', '');
     }
     $this->refs = $refs;
 }
Beispiel #2
0
 public function testShouldBeConvertableToHex()
 {
     $this->assertEquals(Git::sha2bin('747e95f8ffd8d29f62135b2f9c9b216f8ade17bd'), pack('H40', '747e95f8ffd8d29f62135b2f9c9b216f8ade17bd'));
 }
Beispiel #3
0
$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();
echo "Created {$c}\n";
$oc = $c;
$firstcommit = $c->sha();
Beispiel #4
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());
Beispiel #5
0
#!/usr/bin/php
<?php 
/*
 * This file is part of the Git4P library.
 *
 * Copyright (c) 2015 Martijn van der Kleijn <*****@*****.**>
 * Licensed under the MIT license <http://opensource.org/licenses/MIT>
 */
/* QUICK TEST/EXAMPLE FILE */
include 'src/git4p.php';
use Git4p\Git;
use Git4p\GitCommit;
// Test setup
$dir = dirname(__FILE__) . '/mytestrepo';
$git = false;
$git = new Git($dir);
$tip = $git->getTip('master');
echo "Commit tree for master branch\n";
echo "-----------------------------\n\n";
$c = new GitCommit($git);
$c = $c->load($tip);
showLog($c);
function showLog($c)
{
    echo '* ' . $c->shortSha() . "\n";
    if (count($c->parents()) >= 1) {
        echo "| \n";
        $p = $c->parents();
        $c2 = new GitCommit($c->git());
        $c2 = $c2->load($p[0]);
        showLog($c2);