Skip to content

Commit 8860947

Browse files
committed
Create Config module
1 parent a1950bb commit 8860947

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/GitFollow/Config.pm

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
###
2+
### git-follow - Follow lifetime changes of a pathspec in Git.
3+
###
4+
### Copyright (C) 2023 Nickolas Burr <nickolasburr@gmail.com>
5+
###
6+
package GitFollow::Config;
7+
8+
use 5.008;
9+
use strict;
10+
use warnings;
11+
use Exporter qw(import);
12+
use GitFollow::Environment qw($GIT_PATH);
13+
14+
our @EXPORT = qw(
15+
get_config
16+
has_config
17+
);
18+
19+
sub get_config;
20+
sub has_config;
21+
22+
# Get git-config(1) value.
23+
sub get_config {
24+
my ($grp, $key) = @_;
25+
my $config = undef;
26+
27+
system("$GIT_PATH config follow.$grp.$key >/dev/null");
28+
29+
$config = (!$?)
30+
? `$GIT_PATH config follow.$grp.$key`
31+
: `$GIT_PATH config follow.$grp$key`;
32+
33+
# Strip trailing newline from config value.
34+
chomp $config;
35+
return $config;
36+
}
37+
38+
# Check if git-config(1) key exists.
39+
sub has_config {
40+
my ($grp, $key) = @_;
41+
42+
system("$GIT_PATH config follow.$grp.$key >/dev/null");
43+
return 1 unless $?;
44+
45+
system("$GIT_PATH config follow.$grp$key >/dev/null");
46+
!($? >> 8);
47+
}
48+
49+
1;

0 commit comments

Comments
 (0)