blib/lib/Shipwright/Source/Git.pm

filter: Statementstmt 42.0% 29 / 69 Branchbran 8.3% 1 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 100% 2 / 2 totaltotal 42.7% 41 / 96 CC 8 SCAR 19.6
CC
8
Cov
37%
__ANON__
20.0
_run
12.0
run
6.0
CRAP 7.1
« blib/lib/Shipwright/Util.pm ↑ Summary blib/lib/Shipwright/Source/HTTP.pm »
1 package Shipwright::Source::Git;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Shipwright::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use File::Spec::Functions qw/catdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Path qw/remove_tree/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Copy::Recursive qw/rcopy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use base qw/Shipwright::Source::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Cwd qw/getcwd/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head2 new
14  
15 =cut
16  
17 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
18 1 my $class = shift;
19 1 my $self = $class->SUPER::new(@_);
20  
21 1 ▶ $self->name( $self->just_name( $self->source ) ) unless $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name 1 0 1
22 1 return $self;
23 }
24  
25 =head2 run
26  
27 =cut
28  
29 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
30 0 my $self = shift;
31 0 $self->log->info( "preparing to run source: " . $self->source );
32 0 $self->_update_url( $self->name, 'git:' . $self->source );
33  
34 0 $self->_run();
35 0 my $s;
36 0 ▶ if ( $self->is_compressed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_compressed) { } 0 0 0
37 0 require Shipwright::Source::Compressed;
38 0 $s = Shipwright::Source::Compressed->new( %$self, _no_update_url => 1 );
39 }
40 else {
41 0 require Shipwright::Source::Directory;
42 0 $s = Shipwright::Source::Directory->new( %$self, _no_update_url => 1 );
43 }
44 0 $s->run(@_);
45 }
46  
47 =head2 _run
48  
49 =cut
50  
51 0 ▶sub _run {
Subroutine _run: not called CC=3 SCAR=24.8
52 0 my $self = shift;
53 0 my $source = $self->source;
54  
55 0 my $path = catdir( $self->download_directory, $self->name );
56  
57 0 my $canonical_name = $source;
58 0 $canonical_name =~ s/:/-/g;
59 0 $canonical_name =~ s![/\\]!_!g;
60  
61 0 my $cloned_path = catdir( $self->download_directory, $canonical_name );
62 0 my @cmds;
63  
64 0 ▶ if ( -e $cloned_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $cloned_path) { } 0 0 0
65 0 ▶ @cmds = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 my $cwd = getcwd();
67 0 chdir $cloned_path;
68 # can be failed if we are not in any branch, e.g. in a tag instead
69 0 run_cmd( [ $ENV{'SHIPWRIGHT_GIT'}, 'pull' ], 1 );
70 0 chdir $cwd;
71 0 };
72 }
73 else {
74 @cmds =
75 0 ( [ $ENV{'SHIPWRIGHT_GIT'}, 'clone', $self->source, $cloned_path ] );
76 }
77  
78 # work out the version stuff
79 0 ▶ push @cmds, sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
80 0 my $cwd = getcwd();
81 0 chdir $cloned_path;
82 0 ▶ if ( $self->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version) { } 0 0 0
83 run_cmd(
84 0 [ $ENV{'SHIPWRIGHT_GIT'}, 'checkout', $self->version ] );
85 }
86 else {
87 my ($version) = run_cmd(
88 0 [ $ENV{'SHIPWRIGHT_GIT'}, 'rev-parse', '--verify', 'HEAD' ] );
89 0 chomp $version;
90 0 $self->version( $version );
91 }
92 0 chdir $cwd;
93 0 ▶ remove_tree( $path ) if -e $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path 0 0 0
94 0 ▶ rcopy( $cloned_path, $path ) or confess_or_die $!;
Branch: 1 branch
BranchTrueFalseTotal
rcopy($cloned_path, $path) or confess_or_die($!) 0 0 0
95 0 remove_tree( catdir( $path, '.git' ) );
96 0 };
97  
98 0 $self->source( $path );
99 0 run_cmd($_) for @cmds;
100 }
101  
102 2 1;
103  
104 __END__
« blib/lib/Shipwright/Util.pm ↑ Summary blib/lib/Shipwright/Source/HTTP.pm »