Help language development. Donate to The Perl Foundation

LibGit2 cpan:CTILMES last updated on 2020-08-18

use Test;
use Test::When <online>;
use File::Temp;
use LibGit2;

plan 23;

my $remote-url = '';

my $repodir = tempdir;

ok my $repo = Git::Repository.clone($remote-url, $repodir), 'clone';

isa-ok my $remote = $repo.remote-lookup('origin'),
    'Git::Remote', 'remote-lookup';

is $, 'origin', 'name';

is $remote.url, $remote-url, 'url';

isa-ok $remote.autotag, Git::Remote::Autotag::Option, 'autotag';

lives-ok { $remote.connect(dir => 'fetch') }, 'remote connect';

is $remote.connected, True, 'connected';

is $remote.default-branch, 'refs/heads/master', 'default-branch';

is-deeply ${.name}).sort,
	('HEAD', 'refs/heads/master', 'refs/tags/0.1', 'refs/tags/0.2',
	'remote ls';

lives-ok { $ }, 'download';

lives-ok { $remote.disconnect }, 'remote disconnect';

is $remote.connected, False, 'disconnected';

is $remote.get-fetch-refspecs, <+refs/heads/*:refs/remotes/origin/*>,

for $remote.refspecs
    is $_, '+refs/heads/*:refs/remotes/origin/*', 'Str';
    is .direction, 'fetch', 'direction';
    is .dst, 'refs/remotes/origin/*', 'dst';
    is .dst-matches('refs/remotes/origin/master'), True, 'dst-matches';
    is .force, True, 'force';
    is .rtransform('refs/remotes/origin/master'), 'refs/heads/master',
    is .src, 'refs/heads/*', 'src';
    is .src-matches('refs/heads/master'), True, 'src-matches';
    is .transform('refs/heads/master'), 'refs/remotes/origin/master',

lives-ok { $remote.fetch }, 'fetch';