コード例 #1
0
ファイル: GitTest.php プロジェクト: rsky/php-git
 public function testInitRepository()
 {
     require_once __DIR__ . "/lib/MemoryBackend.php";
     require_once __DIR__ . "/lib/MemcachedBackend.php";
     if (!is_dir(__DIR__ . "/git_init_test")) {
         mkdir(__DIR__ . "/git_init_test", 0755);
     }
     $backend = new Git\Backend\Memory(5);
     $repository = Git\Repository::init(__DIR__ . "/git_init_test", true);
     //$repository->addBackend($backend);
     $blob = new Git\Blob($repository);
     $blob->setContent("First Object1");
     $hash = $blob->write();
     $this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $hash, "First Object1 write correctly");
     $this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $blob->getid(), "rawobject and blob hash are same.");
     //$this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $backend->get($hash)->getId(),"Backend return same rawobject");
     $tree = new Git\Tree($repository);
     $entry = new Git\Tree\Entry();
     $entry->name = "README";
     $entry->mode = 0644;
     $entry->oid = $hash;
     $tree->add($entry);
     $tree_hash = $tree->write();
     $this->assertEquals("1d9b59c9d46969914a4f0875faa89f6a3bdd7b70", $tree_hash, "tree writing");
     $commit = new Git\Commit($repository);
     $commit->setAuthor(new Git\Signature("Someone", "*****@*****.**", new DateTime("@1295103057")));
     $commit->setCommitter(new Git\Signature("Someone", "*****@*****.**", new DateTime("@1295103057")));
     $commit->setTree($tree->getId());
     $commit->setParent("");
     // first commit;
     $commit->setMessage("initial import");
     $master_hash = $commit->write();
     $this->markTestIncomplete("this test does not implemente yet.");
     $this->assertEquals("0d02e26cb684486889ea71168df7721a098bee80", $master_hash, "commit writing");
     unset($repository);
     $rmdir = function ($dir) use(&$rmdir) {
         if (is_dir($dir)) {
             $objects = scandir($dir);
             foreach ($objects as $object) {
                 if ($object != "." && $object != "..") {
                     if (filetype($dir . "/" . $object) == "dir") {
                         $rmdir($dir . "/" . $object);
                     } else {
                         unlink($dir . "/" . $object);
                     }
                 }
             }
             reset($objects);
             rmdir($dir);
         }
     };
     $rmdir(__DIR__ . "/git_init_test");
 }
コード例 #2
0
ファイル: GitTest.php プロジェクト: richardfullmer/php-git
 public function testInitRepository()
 {
     require_once __DIR__ . "/lib/MemoryBackend.php";
     //require_once __DIR__ . "/lib/MemcachedBackend.php";
     $this->rmdir(__DIR__ . "/git_init_test");
     mkdir(__DIR__ . "/git_init_test", 0755);
     $backend = new Git\Backend\Memory();
     $repository = Git\Repository::init(__DIR__ . "/git_init_test", true);
     $repository->addBackend($backend, 5);
     $blob = new Git\Blob($repository);
     $blob->setContent("First Object1");
     $hash = $blob->write();
     $this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $hash, "First Object1 write correctly");
     $this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $blob->getid(), "rawobject and blob hash are same.");
     $data = $backend->read($hash);
     if ($backend->read($hash)) {
         $this->assertEquals("abd5864efb91d0fae3385e078cd77bf7c6bea826", $backend->read($hash)->getId(), "Backend return same rawobject");
     }
     $tree = new Git\Tree($repository);
     $tree->add($hash, "README", 100644);
     $tree_hash = $tree->write();
     $this->assertEquals("3c7493d000f58ae3eed94b0a3bc77d60694d33b4", $tree_hash, "tree writing");
     $data = $backend->read("3c7493d000f58ae3eed94b0a3bc77d60694d33b4");
     if ($data) {
         $this->assertEquals("3c7493d000f58ae3eed94b0a3bc77d60694d33b4", $data->getId(), "Backend return same tree raw");
     }
     $commit = new Git\Commit($repository);
     $commit->setAuthor(new Git\Signature("Someone", "*****@*****.**", new DateTime("2011-01-01 00:00:00", new DateTimezone("Asia/Tokyo"))));
     $commit->setCommitter(new Git\Signature("Someone", "*****@*****.**", new DateTime("2011-01-01 00:00:00", new DateTimezone("Asia/Tokyo"))));
     $commit->setTree($tree->getId());
     // when first commit. you dont call setParent.
     //$commit->setParent("");
     $commit->setMessage("initial import");
     $master_hash = $commit->write();
     //$this->markTestIncomplete("this test does not implemente yet.");
     $this->assertEquals("c12883a96cf60d1b2edba971183ffaca6d1b077e", $master_hash, "commit writing");
     /*
             $re = new Git\Reference($repository);
             $re->setName("refs/heads/master");
             //$re->setTarget("refs/heads/master");
             // you can't use setOid if setTarget called.
             $re->setOID("c12883a96cf60d1b2edba971183ffaca6d1b077e");
             $re->write();
     */
     $this->rmdir(__DIR__ . "/git_init_test");
 }