<?php

declare(strict_types=1);
namespace Tests\git2;
use git2\git;
use git2\git_indexer;
use git2\git_indexer_options;
use git2\git_indexer_progress;

final class IndexerTest extends GitTestCase
{

	public function testIndexer(): void
	{
		git::repository_init($repo, $this->mkdir('repo'), true);
		git::packbuilder_new($pb, $repo);
		$this->assertOK(git::packbuilder_write_buf($buf, $pb));

		$this->assertOK(git::indexer_options_init($opts, git_indexer_options::VERSION));
		$this->assertInstanceOf(git_indexer_options::class, $opts);

		git::odb_new($odb);

		$this->assertOK(git::indexer_new($indexer, $this->mkdir('indexer'), 0, $odb, $opts));
		$this->assertInstanceOf(git_indexer::class, $indexer);
		$this->assertOK(git::indexer_append($indexer, (string) $buf, $stats));
		$this->assertInstanceOf(git_indexer_progress::class, $stats);
		$this->assertOK(git::indexer_commit($indexer, $stats2));
		$this->assertInstanceOf(git_indexer_progress::class, $stats2);
		$this->assertSame('029d08823bd8a8eab510ad6ac75c823cfd3ed31e', git::oid_tostr_s(git::indexer_hash($indexer)));
	}

}