Skip to content

Commit 9fef9e2

Browse files
cowosegitster
authored andcommitted
Add Git::config_path()
Use --path option when calling 'git config' thus allow for pathname expansion, e.g. a tilde. Signed-off-by: Cord Seele <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 85e9c7e commit 9fef9e2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

perl/Git.pm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,38 @@ sub config_bool {
627627
};
628628
}
629629

630+
631+
=item config_path ( VARIABLE )
632+
633+
Retrieve the path configuration C<VARIABLE>. The return value
634+
is an expanded path or C<undef> if it's not defined.
635+
636+
This currently wraps command('config') so it is not so fast.
637+
638+
=cut
639+
640+
sub config_path {
641+
my ($self, $var) = _maybe_self(@_);
642+
643+
try {
644+
my @cmd = ('config', '--path');
645+
unshift @cmd, $self if $self;
646+
if (wantarray) {
647+
return command(@cmd, '--get-all', $var);
648+
} else {
649+
return command_oneline(@cmd, '--get', $var);
650+
}
651+
} catch Git::Error::Command with {
652+
my $E = shift;
653+
if ($E->value() == 1) {
654+
# Key not found.
655+
return undef;
656+
} else {
657+
throw $E;
658+
}
659+
};
660+
}
661+
630662
=item config_int ( VARIABLE )
631663
632664
Retrieve the integer configuration C<VARIABLE>. The return value

0 commit comments

Comments
 (0)