blib/lib/Amon2/Setup/VC/Git.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 85 CC 6 SCAR 24.7
CC
6
Cov
0%
_is_git_available
30.0
do_import
6.0
new
2.0
CRAP 11.9
1 package Amon2::Setup::VC::Git;
2 use strict;
3 use warnings;
4 use utf8;
5 use File::Temp qw(tempfile);
6  
7 sub new {
8 bless {}, $_[0];
9 }
10  
11 sub do_import {
12 my ($self) = @_;
13  
14 unless ($self->_is_git_available('git')) {
15 warn "There is no git command.\n";
16 return;
17 }
18  
19 !system("git init") or die $?;
20 !system("git add .") or die $?;
21 !system(q{git commit -m "initial import"}) or die $?;
22 }
23  
24 sub _is_git_available {
25 my ($self) = @_;
26  
27 if ($^O eq 'MSWin32') {
28 no warnings;
29 !system('git --version 2>&1 > NUL');
30 } else {
31 my $pid = fork();
32 die "Cannot fork: $!" if !defined $pid;
33 if ($pid) { # parent
34 waitpid($pid, 0);
35 require POSIX;
36 POSIX::WIFEXITED($?) && POSIX::WEXITSTATUS($?)==0 ? 1 : 0;
37 } else { # child
38 my ($logfh, $logfile) = tempfile(UNLINK => 1);
39 open STDOUT, '>', $logfile or die "$!";
40 open STDERR, '>&STDOUT' or die "$!";
41 no warnings;
42 exec('git', '--version');
43 exit(9);
44 }
45 }
46 }
47  
48 1;
49