Users probe tests
[scpubgit/System-Introspector.git] / lib / System / Introspector / Repositories / Git.pm
CommitLineData
5843e886 1package System::Introspector::Repositories::Git;
2use Moo;
3
4sub gather {
5 my ($self) = @_;
6 my $pipe = $self->_open_locate_git_config_pipe;
7 my %location;
8 while (defined( my $line = <$pipe> )) {
9 chomp $line;
10 next unless $line =~ m{^(.+)/\.git/config$};
11 my $base = $1;
12 $location{ $base } = $self->_gather_git_info($line);
13 }
14 return \%location;
15}
16
17sub _gather_git_info {
18 my ($self, $config) = @_;
19 return {
20 config_file => $config,
21 config => $self->_gather_git_config($config),
22 };
23}
24
25sub _gather_git_config {
26 my ($self, $config) = @_;
27 my $pipe = $self->_open_git_config_pipe($config);
28 my %config;
29 while (defined( my $line = <$pipe> )) {
30 chomp $line;
31 my ($name, $value) = split m{=}, $line, 2;
32 $config{ $name } = $value;
33 }
34 return \%config;
35}
36
37sub _open_git_config_pipe {
38 my ($self, $config) = @_;
39 my $command = "git config --file $config --list";
40 open my $pipe, '-|', $command
41 or die "Unable to open pipe to '$command': $!\n";
42 return $pipe;
43}
44
45sub _open_locate_git_config_pipe {
46 my ($self) = @_;
47 my $command = 'locate .git/config';
48 open my $pipe, '-|', $command
49 or die "Unable to open pipe to '$command': $!\n";
50 return $pipe;
51}
52
531;