| 1 | package Dist::Conformance::Source::Git 0.006; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Standards fetched from a git repository into a cache directory | ||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use 5.040; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use re '/aasx'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Mojo::Base 'Dist::Conformance::Source', -signatures; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Digest::SHA(); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use IPC::Run3(); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Mojo::File(); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 4 | has 'url'; | |||||||||||||||||||||||||||||
| 16 | 4 | has ref => 'HEAD'; | |||||||||||||||||||||||||||||
| 17 | 4 | has offline => 0; | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | has cache => sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $base = $ENV{XDG_CACHE_HOME} || Mojo::File->new( $ENV{HOME} // die("Neither XDG_CACHE_HOME nor HOME is set\n") )->child('.cache'); | ||||||||||||||||||||||||||||
|
Condition0%0/5
$ENV{'XDG_CACHE_HOME'} || 'Mojo::File'->new($ENV{'HOME'} // die("Neither XDG_CACHE_HOME nor HOME is set\n"))->child('.cache')
$ENV{"HOME"} // die("Neither XDG_CACHE_HOME nor HOME is set\n")
MC/DC0%0/2
$ENV{'XDG_CACHE_HOME'} || 'Mojo::File'->new($ENV{'HOME'} // die("Neither XDG_CACHE_HOME nor HOME is set\n"))->child('.cache')
$ENV{'XDG_CACHE_HOME'}
'Mojo::File'->new($ENV{'HOME'} // die("Neither XDG_CACHE_HOME nor HOME is set\n"))->child('.cache')
MC/DC0%0/1
$ENV{"HOME"} // die("Neither XDG_CACHE_HOME nor HOME is set\n")
$ENV{"HOME"}
Truth table0%0/3
A || B
A= $ENV{'XDG_CACHE_HOME'}B= 'Mojo::File'->new($ENV{'HOME'} // die("Neither XDG_CACHE_HOME nor HOME is set\n"))->child('.cache')
Truth table0%0/2
A
A= $ENV{"HOME"}
| |||||||||||||||||||||||||||||||
| 20 | 0 | return Mojo::File->new($base)->child('dist-conformance')->to_string; | |||||||||||||||||||||||||||||
| 21 | 4 | }; | |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub new ( $class, @args ) { | ||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 25 | 0 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | die "url is required\n" if !defined $self->url || $self->url eq q{}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->url or $self->url eq ""
MC/DC0%0/2
not defined $self->url or $self->url eq ""
not defined $self->url
$self->url eq ""
Truth table0%0/3
not(A) or B
A= not defined $self->urlB= $self->url eq ""
| |||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | die( 'The url ' . $self->url . " starts with -\n" ) if index( $self->url, q{-} ) == 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | die( 'The ref ' . $self->ref . " starts with -\n" ) if index( $self->ref, q{-} ) == 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 29 | 0 | return $self; | |||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub clone_dir ($self) { | ||||||||||||||||||||||||||||
|
Subroutine
clone_dir: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 34 | 0 | return Mojo::File->new( $self->cache )->child( Digest::SHA::sha1_hex( $self->url . "\n" . $self->ref ) ); | |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub root ($self) { | ||||||||||||||||||||||||||||
|
Subroutine
root: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | return $self->{root} //= do { | ||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"root"} //= do {
my $dir = $self->clone_dir;
if ($self->offline) {
die 'Offline, and there is no cached copy of ' . $self->describe, "\n" unless -d $dir->child(".git");
}
else {
$self->fetch;
};
$dir
}
MC/DC0%0/2
$self->{"root"} //= do {
my $dir = $self->clone_dir;
if ($self->offline) {
die 'Offline, and there is no cached copy of ' . $self->describe, "\n" unless -d $dir->child(".git");
}
else {
$self->fetch;
};
$dir
}
$self->{"root"}
do {
my $dir = $self->clone_dir;
if ($self->offline) {
die 'Offline, and there is no cached copy of ' . $self->describe, "\n" unless -d $dir->child(".git");
}
else {
$self->fetch;
};
$dir
}
Truth table0%0/3
A //= B
A= $self->{"root"}B= do {
my $dir = $self->clone_dir;
if ($self->offline) {
die 'Offline, and there is no cached copy of ' . $self->describe, "\n" unless -d $dir->child(".git");
}
else {
$self->fetch;
};
$dir
}
| |||||||||||||||||||||||||||||||
| 40 | 0 | my $dir = $self->clone_dir; | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( $self->offline ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | die( 'Offline, and there is no cached copy of ' . $self->describe, "\n" ) if !-d $dir->child('.git'); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||||
| 45 | 0 | $self->fetch; | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | 0 | $dir; | |||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub fetch ($self) { | ||||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 53 | 0 | my $dir = $self->clone_dir; | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( !-d $dir->child('.git') ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 55 | 0 | $dir->remove_tree; | |||||||||||||||||||||||||||||
| 56 | 0 | $dir->dirname->make_path; | |||||||||||||||||||||||||||||
| 57 | 0 | git( qw{clone --quiet --no-checkout --}, $self->url, "$dir" ); | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||
| 59 | 0 | git( '-C', "$dir", qw{fetch --quiet origin}, $self->ref ); | |||||||||||||||||||||||||||||
| 60 | 0 | git( '-C', "$dir", qw{checkout --quiet --force --detach FETCH_HEAD} ); | |||||||||||||||||||||||||||||
| 61 | 0 | return $dir; | |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub describe ($self) { | ||||||||||||||||||||||||||||
|
Subroutine
describe: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $self->url . ' at ' . $self->ref . ( $self->path ne q{} ? ' (path ' . $self->path . ')' : q{} ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | # A clone and a fetch need the transports, the credential helpers and the | ||||||||||||||||||||||||||||||
| 71 | # configuration of the real git, which no CPAN module reproduces. | ||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub git (@arguments) { | ||||||||||||||||||||||||||||
|
Subroutine
git: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 73 | 0 | local $ENV{GIT_TERMINAL_PROMPT} = 0; | |||||||||||||||||||||||||||||
| 74 | 0 | my ( $out, $err ) = ( q{}, q{} ); | |||||||||||||||||||||||||||||
| 75 | 0 | IPC::Run3::run3( [ 'git', @arguments ], \undef, \$out, \$err ); | |||||||||||||||||||||||||||||
| 76 | 0 | my $status = $?; | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | die( "git @arguments failed: " . ( $err =~ s/\s+\z//r ), "\n" ) if $status; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 78 | 0 | return $out; | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||||