Help language development. Donate to The Perl Foundation

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

use Test;
use File::Temp;
use LibGit2;

my ($config_file, $filehandle) = tempfile;

ok my $config =, 'new';

lives-ok { $config.add-file-ondisk($config_file, GIT_CONFIG_LEVEL_APP) },

lives-ok { $config.set('', 'this') }, 'set string';
lives-ok { $config.set('a.b', True)       }, 'set bool true';
lives-ok { $config.set('a.c', False)      }, 'set bool false';
lives-ok { $config.set('b.d', 27)         }, 'set int';

ok my $conf2 =, 'second config';

lives-ok { $conf2.add-file-ondisk($config_file, GIT_CONFIG_LEVEL_APP) },

ok my $entry = $conf2.get-entry(''), 'get-entry';
is $, '', 'entry name';
is $entry.value, 'this', 'entry value';
is $entry.level, GIT_CONFIG_LEVEL_APP, 'entry level';

my %config = ${ $ => $_.value });

is %config<>, 'this', 'get string';
is %config<a.b>, 'true', 'get bool true';
is %config<a.c>, 'false', 'get bool false';
is %config<b.d>, 27, 'get int';

is $conf2<>, 'this', 'associative get';
is $conf2<missing.config>, Nil, 'associate get missing';

is $conf2<>:exists, True, 'associative exists';
is $conf2<missing.config>:exists, False, 'associative exists missing';

is $conf2<>:delete, 'this', 'associative delete';
is $conf2<missing.config>:delete, Nil, 'associative delete missing';

is $conf2<>, Nil, 'associative deleted';