diff options
author | Cord Seele <cowose@googlemail.com> | 2011-09-30 12:52:24 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-09-30 12:34:38 -0700 |
commit | 9fef9e279055423363e110b7246a9b8bbcf0bd72 (patch) | |
tree | 2f8610b117bcbdfeadd8feb6cdd55e0bdf7d423b /perl | |
parent | Git 1.7.7-rc3 (diff) | |
download | tgif-9fef9e279055423363e110b7246a9b8bbcf0bd72.tar.xz |
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 <cowose@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'perl')
-rw-r--r-- | perl/Git.pm | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/perl/Git.pm b/perl/Git.pm index a86ab709c2..c279bfb244 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -627,6 +627,38 @@ sub config_bool { }; } + +=item config_path ( VARIABLE ) + +Retrieve the path configuration C<VARIABLE>. The return value +is an expanded path or C<undef> if it's not defined. + +This currently wraps command('config') so it is not so fast. + +=cut + +sub config_path { + my ($self, $var) = _maybe_self(@_); + + try { + my @cmd = ('config', '--path'); + unshift @cmd, $self if $self; + if (wantarray) { + return command(@cmd, '--get-all', $var); + } else { + return command_oneline(@cmd, '--get', $var); + } + } catch Git::Error::Command with { + my $E = shift; + if ($E->value() == 1) { + # Key not found. + return undef; + } else { + throw $E; + } + }; +} + =item config_int ( VARIABLE ) Retrieve the integer configuration C<VARIABLE>. The return value |