Minilla/Git.pm

filter: Statementstmt 33.3% 20 / 60 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 35.2% 6 / 17 Podpod 0.0% 0 / 11 totaltotal 21.4% 26 / 121 CC 17 SCAR 31.5
CC
17
Cov
22%
git_file_modes
72.0
git_show_toplevel
20.0
git_submodules
12.0
CRAP 23.3
« Minilla/Metadata.pm ↑ Summary Minilla/Migrate.pm »
1 package Minilla::Git;
2 71 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 71 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 71 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 71 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 71 our @EXPORT = qw(git_ls_files git_file_modes git_init git_add git_rm git_commit git_config git_remote git_submodules git_submodule_files git_show_toplevel);
9  
10 71 ▶use Minilla::Logger qw(errorf);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 71 ▶use Minilla::Util qw(cmd);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub git_init {
Subroutine git_init: not called CC=1 SCAR=6.9
Pod undocumented
14 0 cmd('git', 'init');
15 }
16  
17 0 ▶sub git_add {
Subroutine git_add: not called CC=2 SCAR=17.9
Pod undocumented
18 0 ▶ cmd('git', 'add', @_ ? @_ : '.');
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
19 }
20  
21 0 ▶sub git_config {
Subroutine git_config: not called CC=2 SCAR=17.9
Pod undocumented
22 0 ▶ cmd('git', 'config', @_ ? @_ : '.');
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
23 }
24  
25 0 ▶sub git_rm {
Subroutine git_rm: not called CC=1 SCAR=6.9
Pod undocumented
26 0 cmd('git', 'rm', @_);
27 }
28  
29 0 ▶sub git_commit {
Subroutine git_commit: not called CC=1 SCAR=6.9
Pod undocumented
30 0 cmd('git', 'commit', @_);
31 }
32  
33 0 ▶sub git_remote {
Subroutine git_remote: not called CC=1 SCAR=6.9
Pod undocumented
34 0 cmd('git', 'remote', @_);
35 }
36  
37 0 ▶sub git_ls_files {
Subroutine git_ls_files: not called CC=1 SCAR=6.9
Pod undocumented
38 0 my @files = split /\0/, `git ls-files -z`;
39 0 return @files;
40 }
41  
42 0 ▶sub git_file_modes {
Subroutine git_file_modes: not called CC=8 SCAR=42.8
Pod undocumented
43 0 ▶ open my $fh, '-|', 'git', 'ls-files', '--stage', '--recurse-submodules', '-z'
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "-|", "git", "ls-files", "--stage", "--recurse-submodules", "-z" or die "Cannot read Git index: $!\n" 0 0 0
44 or die "Cannot read Git index: $!\n";
45 0 local $/ = "\0";
46 0 my %modes;
47 0 ▶ while (my $entry = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readline $fh)) 0 0 0
48 0 $entry =~ s/\0\z//;
49 0 my ($mode, $stage, $path) = $entry =~ /\A([0-9]+) [0-9a-f]+ ([0-3])\t(.*)\z/s;
50 0 ▶ next unless defined $path && $stage == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and $stage == 0 0 0 0
Condition0%0/3
defined $path and $stage == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $path and $stage == 0
defined $path $stage == 0
Truth table0%0/3
A and B
A= defined $pathB= $stage == 0
ABresult
0X0
100
111
51 0 ▶ $path =~ s!\\!/!g if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 0 0
52 0 ▶ $modes{$path} = $mode eq '100755' ? 0755 : 0644;
Branch: 1 branch
BranchTrueFalseTotal
$mode eq '100755' ? : 0 0 0
53 }
54 0 ▶ close $fh or die "Cannot read Git index\n";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Cannot read Git index\n" 0 0 0
55 0 return \%modes;
56 }
57  
58 0 ▶sub git_submodules {
Subroutine git_submodules: not called CC=3 SCAR=24.8
Pod undocumented
59 0 my @submodules = split /\n/, `git submodule status --recursive`;
60 0 my @files;
61 0 for (@submodules) {
62 0 my ($path) = $_ =~ /^[+\-U\x20][0-9a-f]{40}\x20([^\x20]+).*$/;
63 0 ▶ push @files, $path if $path;
Branch: 1 branch
BranchTrueFalseTotal
if $path 0 0 0
64 }
65 0 return @files;
66 }
67  
68 0 ▶sub git_submodule_files {
Subroutine git_submodule_files: not called CC=3 SCAR=24.8
Pod undocumented
69 # XXX: `git ls-files -z` does *NOT* print new line in last.
70 # So it breaks format when multiple submodules contains and combined with `git submodule foreach`. (and failed to parse.)
71 0 my @output = split /\n/, `git submodule foreach --recursive "git ls-files -z"`;
72 0 ▶ for (my $i = 1; $i <= @output-2; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= @output - 2) 0 0 0
73 0 $output[$i] =~ s/\0([^\0]*)$//;
74 0 splice @output, $i+1, 0, $1;
75 }
76  
77 0 my @files;
78 0 ▶ while (@output) {
Branch: 1 branch
BranchTrueFalseTotal
if (@output) 0 0 0
79 0 my $submodule_line = shift @output;
80 0 my ($submodule_name) = $submodule_line =~ /'(.+)'/;
81 0 push @files, map "$submodule_name/$_", split /\0/, shift @output;
82 }
83 0 return @files;
84 }
85  
86 0 ▶sub git_show_toplevel {
Subroutine git_show_toplevel: not called CC=4 SCAR=30.0
Pod undocumented
87 0 my $top_level = `git rev-parse --show-toplevel`;
88 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
89 0 ▶ errorf("Top-level git directory could not be found for %s: %s\n", Cwd::getcwd(),
Branch: 2 branches
BranchTrueFalseTotal
$? == -1 ? : 0 0 0
$? & 127 ? : 0 0 0
90 $? == -1 ? "$!" :
91 $? & 127 ? "git received signal ". ($? & 127) : "git exited ". ($? >> 8))
92 }
93 0 chomp $top_level;
94 0 return $top_level;
95 }
96  
97 71 1;
« Minilla/Metadata.pm ↑ Summary Minilla/Migrate.pm »