Introspector/Probe/Repositories/Git.pm

filter: Statementstmt 67.2% 41 / 61 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.7% 11 / 17 Podpod 0.0% 0 / 1 totaltotal 62.6% 57 / 91 CC 8 SCAR 10.3
CC
8
Cov
63%
_find_commit_count
6.0
_find_changes
6.0
_find_tracking
4.7
CRAP 2.8
« Introspector/Probe/LibDirs/Perl.pm ↑ Summary Introspector/Probe/Sudoers.pm »
1 package System::Introspector::Probe::Repositories::Git;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use System::Introspector::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
5 handle_from_command
6 transform_exceptions
7 lines_from_command
8 1 );
9  
10 has root => (
11 is => 'ro',
12 0 ▶ default => sub { '/' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
13 1 );
14  
15 1 ▶sub gather {
Subroutine gather: called CC=1 SCAR=0.0
Pod undocumented
16 1 my ($self) = @_;
17 1 ▶ return transform_exceptions {
Subroutine __ANON__: called CC=3 SCAR=11.0
18 1 my $pipe = $self->_open_locate_git_config_pipe;
19 1 my %location;
20 1 ▶ while (defined( my $line = <$pipe> )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $pipe)) 1 1 2
21 1 chomp $line;
22 1 ▶ next unless $line =~ m{^(.+)/\.git/config$};
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ m[^(.+)/\.git/config$] 0 1 1
23 1 my $base = $1;
24 1 $location{ $base } = $self->_gather_git_info($line);
25 }
26 1 return { git => \%location };
27 1 };
28 }
29  
30 1 ▶sub _gather_git_info {
Subroutine _gather_git_info: called CC=1 SCAR=0.0
31 1 my ($self, $config) = @_;
32 return {
33 config_file => $config,
34 1 ▶ config => transform_exceptions {
Subroutine __ANON__: called CC=1 SCAR=0.0
35 1 $self->_gather_git_config($config);
36 },
37 1 ▶ tracked => transform_exceptions {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 1 $self->_gather_track_info($config);
39 },
40 1 };
41 }
42  
43 1 ▶sub _gather_track_info {
Subroutine _gather_track_info: called CC=1 SCAR=0.0
44 1 my ($self, $config) = @_;
45 1 (my $git_dir = $config) =~ s{/config$}{};
46 1 return $self->_find_tracking($git_dir);
47 }
48  
49 1 ▶sub _find_tracking {
Subroutine _find_tracking: called CC=3 SCAR=15.4
50 1 my ($self, $dir) = @_;
51 1 local $ENV{GIT_DIR} = $dir;
52 1 my @lines = lines_from_command
53 ['git', 'for-each-ref',
54 '--format', q{OK %(refname:short) %(upstream:short)},
55 'refs/heads',
56 ];
57 1 my %branch;
58 1 for my $line (@lines) {
59 0 ▶ if ($line =~ m{^OK\s+(\S+)\s+(\S+)?$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^OK\s+(\S+)\s+(\S+)?$/) { } 0 0 0
60 0 my ($local, $remote) = ($1, $2);
61 $branch{ $local } = {
62 upstream => $remote,
63 0 ▶ changed_files => transform_exceptions {
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 $self->_find_changes($dir, $local, $remote);
65 },
66 0 ▶ local_commit_count => transform_exceptions {
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 $self->_find_commit_count($dir, $local, $remote);
68 },
69 }
70 0 }
71 else {
72 0 return { __error__ => join "\n", @lines };
73 }
74 }
75 1 return { branches => \%branch };
76 }
77  
78 0 ▶sub _find_commit_count {
Subroutine _find_commit_count: not called CC=2 SCAR=17.9
79 0 my ($self, $dir, $local, $remote) = @_;
80 0 ▶ return { __error__ => "No remote" }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $remote 0 0 0
81 unless defined $remote;
82 0 local $ENV{GIT_DIR} = $dir;
83 0 my @lines = lines_from_command
84 ['git', 'log', '--oneline', "$remote..$local"];
85 0 return scalar @lines;
86 }
87  
88 0 ▶sub _find_changes {
Subroutine _find_changes: not called CC=2 SCAR=17.9
89 0 my ($self, $dir, $local, $remote) = @_;
90 0 ▶ return { __error__ => "No remote" }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $remote 0 0 0
91 unless defined $remote;
92 0 local $ENV{GIT_DIR} = $dir;
93 0 my @lines = lines_from_command
94 ['git', 'diff', '--name-only', $local, $remote];
95 0 return \@lines;
96 }
97  
98 1 ▶sub _gather_git_config {
Subroutine _gather_git_config: called CC=2 SCAR=6.9
99 1 my ($self, $config) = @_;
100 1 my $pipe = $self->_open_git_config_pipe($config);
101 1 my %config;
102 1 ▶ while (defined( my $line = <$pipe> )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $pipe)) 4 1 5
103 4 chomp $line;
104 4 my ($name, $value) = split m{=}, $line, 2;
105 4 $config{ $name } = $value;
106 }
107 1 return { contents => \%config };
108 }
109  
110 1 ▶sub _open_git_config_pipe {
Subroutine _open_git_config_pipe: called CC=1 SCAR=0.0
111 1 my ($self, $config) = @_;
112 1 return handle_from_command "git config --file $config --list";
113 }
114  
115 0 ▶sub _open_locate_git_config_pipe {
Subroutine _open_locate_git_config_pipe: not called CC=1 SCAR=6.9
116 0 my ($self) = @_;
117 0 (my $root = $self->root) =~ s{/$}{};
118 0 return handle_from_command sprintf
119 q{locate --regex '^%s/.*\\.git/config$'}, $root;
120 }
121  
122 1 1;
123  
124 __END__
« Introspector/Probe/LibDirs/Perl.pm ↑ Summary Introspector/Probe/Sudoers.pm »