예제 #1
0
 public function testGitGetCommitFlomRepository()
 {
     $repository = new Git\Repository(".git");
     $commit = $repository->getCommit("1f27eed71970a0dbc0ca758f449e4b68c4c91bd8");
     $author = $commit->getAuthor();
     $this->assertEquals("Shuhei Tanuma", $author->name);
     $this->assertEquals("*****@*****.**", $author->email);
     $committer = $commit->getCommitter();
     $this->assertEquals("Shuhei Tanuma", $committer->name);
     $this->assertEquals("*****@*****.**", $committer->email);
     $this->assertEquals("1f27eed71970a0dbc0ca758f449e4b68c4c91bd8", $commit->getId());
     $tree = $commit->getTree();
     $entry1 = $tree->getEntry(0);
     $this->assertEquals("EXPERIMENTAL", $entry1->name);
     $this->assertEquals("35a136e7e190505e46367a04f730e827062b13cc", $entry1->oid);
     $entry2 = $tree->getEntry(1);
     $this->assertEquals("README.md", $entry2->name);
     $this->assertEquals("a1a07d27e9d8a78e3bc6fb8a6d8308d358ff9b07", $entry2->oid);
     $commit = $repository->getCommit("bba0bb972cbdc72d908ebd7c89157d7e207f5e92");
     $parent = $commit->getParent();
     $this->assertEquals("b500d73e7125ae105ce125b96390ad09d6174629", $parent->getId());
     $author = $parent->getAuthor();
     $this->assertEquals("Shuhei Tanuma", $author->name);
     $this->assertEquals("*****@*****.**", $author->email);
     $committer = $parent->getCommitter();
     $this->assertEquals("Shuhei Tanuma", $committer->name);
     $this->assertEquals("*****@*****.**", $committer->email);
 }
예제 #2
0
 public function testObjectGetId()
 {
     $git = new Git\Repository(".git");
     //$this->markTestIncomplete("getObjectで問題が発生している");
     $obj = $git->getObject("6c4a06776164f960307341033a7e5271c0b2c669");
     $this->assertEquals("6c4a06776164f960307341033a7e5271c0b2c669", $obj->getId());
 }
예제 #3
0
파일: Object.php 프로젝트: GromNaN/GitCore
 /**
  * Returns the type of this git object, as reported by git cat-file -t
  *
  * @return string
  */
 public function getType()
 {
     if (!isset($this->type)) {
         $output = $this->repository->git('cat-file -t %s', $this->hash);
         $this->type = trim($output);
     }
     return $this->type;
 }
예제 #4
0
 public function testConstruct()
 {
     try {
         $git = new Git\Repository(PHP_GIT_FIXTURE_DIR . "/fixture.git");
         $commit = $git->getCommit("7caa5b63e5fe4596543378e47b5225b6a1fa2dee");
     } catch (\Exception $e) {
         $this->fail();
     }
     unset($git);
 }
예제 #5
0
 /**
  * Reference failed when call getTarget();
  */
 public function testGitReferenceGetTarget()
 {
     $rep = new Git\Repository(dirname(__DIR__) . "/.git/");
     $ref = $rep->lookupRef(self::$reference_name);
     try {
         $target = $ref->getTarget();
         $this->fail("something wrong. this method allowed symbolic reference only.");
     } catch (Exception $e) {
         $this->assertTrue(true, "can't call getTarget method when lookup doesn't symbolic reference");
     }
 }
예제 #6
0
 public function testSort()
 {
     /*
         Git::SORT_NONE
         Git::SORT_TOPO
         Git::SORT_DATE
         Git::SORT_REVERSE
         先にPHPのarrayにしてuserspaceでの対応にするか悩む
     */
     $git = new Git\Repository(".git");
     $walker = $git->getWalker();
     $walker->sort(Git\Revwalk\SORT_NONE);
     $walker->push("1def80657903dcf8d9d87a5e4edfaca92ddcff38");
     $this->assertInstanceof("Git\\Commit", $walker->next());
 }
예제 #7
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");
 }
예제 #8
0
 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");
 }