<?php
declare(strict_types=1);
namespace Tests\git2;
use git2\git;
use git2\git_annotated_commit;
final class AnnotatedCommitTest extends GitTestCase
{
public function testLookup(): void
{
$dir = $this->mkdir('lookup');
git::repository_init($repo, $dir, false);
git::repository_index($index, $repo);
git::index_write_tree($treeId, $index);
git::tree_lookup($tree, $repo, $treeId);
git::signature_now($sig, 'John Doe', 'john.doe@example.com');
git::commit_create_v($id, $repo, 'HEAD', $sig, $sig, null, 'Hello world!', $tree);
$this->assertOK(git::annotated_commit_lookup($commit, $repo, $id));
$this->assertInstanceOf(git_annotated_commit::class, $commit);
$this->assertSame(git::oid_tostr_s($id), git::oid_tostr_s(git::annotated_commit_id($commit)));
}
public function testFromRef(): void
{
$dir = $this->mkdir('lookup');
git::repository_init($repo, $dir, false);
git::repository_index($index, $repo);
git::index_write_tree($treeId, $index);
git::tree_lookup($tree, $repo, $treeId);
git::signature_now($sig, 'John Doe', 'john.doe@example.com');
git::commit_create_v($id, $repo, 'HEAD', $sig, $sig, null, 'Hello world!', $tree);
$this->assertOK(git::repository_head($ref, $repo));
$this->assertOK(git::annotated_commit_from_ref($commit, $repo, $ref));
$this->assertInstanceOf(git_annotated_commit::class, $commit);
$this->assertSame('refs/heads/master', git::annotated_commit_ref($commit));
}
public function testFromRevspec(): void
{
$dir = $this->mkdir('lookup');
git::repository_init($repo, $dir, false);
git::repository_index($index, $repo);
git::index_write_tree($treeId, $index);
git::tree_lookup($tree, $repo, $treeId);
git::signature_now($sig, 'John Doe', 'john.doe@example.com');
git::commit_create_v($id, $repo, 'HEAD', $sig, $sig, null, 'Hello world!', $tree);
$this->assertOK(git::annotated_commit_from_revspec($commit, $repo, 'master'));
$this->assertInstanceOf(git_annotated_commit::class, $commit);
$this->assertNull(git::annotated_commit_ref($commit));
}
}