<?php
declare(strict_types=1);
namespace Tests\git2;
use git2\git;
use git2\git_error_code;
use git2\git_index;
use git2\git_rebase;
use git2\git_rebase_operation;
use git2\git_rebase_options;
final class RebaseTest extends GitTestCase
{
public function testRebase(): void
{
git::repository_init($repo, $dir = $this->mkdir('rebase'), false);
git::repository_index($index, $repo);
git::index_write_tree($treeId, $index);
git::tree_lookup($tree, $repo, $treeId);
git::signature_new($sig, 'John Doe', 'john.doe@example.com', 1640263000, 60);
git::commit_create_v($id, $repo, 'HEAD', $sig, $sig, null, 'Hello world!', $tree);
git::commit_lookup($initial, $repo, $id);
git::branch_create($_, $repo, 'foo', $initial, false);
git::commit_create_v($id2, $repo, 'HEAD', $sig, $sig, null, 'Hello world!', $tree, $initial);
$this->assertOK(git::annotated_commit_from_revspec($master, $repo, 'HEAD'));
$this->assertOK(git::annotated_commit_from_revspec($foo, $repo, 'refs/heads/foo'));
$this->assertOK(git::rebase_options_init($opts, git_rebase_options::VERSION));
$this->assertOK(git::rebase_init($rebase, $repo, $master, null, $foo, $opts));
$this->assertInstanceOf(git_rebase::class, $rebase);
$this->assertSame(1, git::rebase_operation_entrycount($rebase));
$this->assertSame(-1, git::rebase_operation_current($rebase));
$this->assertOK(git::rebase_next($operation, $rebase));
$this->assertInstanceOf(git_rebase_operation::class, $operation);
$this->assertSame(git_error_code::ERROR, git::rebase_inmemory_index($index2, $rebase));
$this->assertSame(0, git::rebase_operation_current($rebase));
$this->assertNotNull(git::rebase_operation_byindex($rebase, 0));
$this->assertNull(git::rebase_operation_byindex($rebase, 1));
$this->assertSame('4ce6effae5129f525fb2174ef364875e31efd1e4', git::oid_tostr_s(git::rebase_onto_id($rebase)));
$this->assertSame('4ce6effae5129f525fb2174ef364875e31efd1e4', git::rebase_onto_name($rebase));
$this->assertSame('5b3b8cfd195c8120aeb20e9022ccf2410ab0e11b', git::oid_tostr_s(git::rebase_orig_head_id($rebase)));
$this->assertNull(git::rebase_orig_head_name($rebase));
$this->assertSame(git_error_code::EAPPLIED, git::rebase_commit($rebasedId, $rebase, $sig, $sig, null, null));
$this->assertSame(git_error_code::ITEROVER, git::rebase_next($_2, $rebase));
$this->assertOK(git::rebase_finish($rebase, $sig));
$this->assertOK(git::rebase_abort($rebase));
}
}