Conformance/Source/Git.pm

filter: Statementstmt 45.2% 24 / 53 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 50.0% 7 / 14 Podpod 100% 6 / 6 totaltotal 34.5% 37 / 107 CC 13 SCAR 24.8
CC
13
Cov
30%
new
30.0
root
20.0
__ANON__
12.0
CRAP 12.0
« Conformance/Check/ClaudeSettings.pm ↑ Summary Conformance/Snapshot/Tree.pm »
1 package Dist::Conformance::Source::Git 0.011;
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')
l!l&&r!l&&!r
000
$ENV{"HOME"} // die("Neither XDG_CACHE_HOME nor HOME is set\n")
l!l
00
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')
ABresult
1X1
011
000
Truth table0%0/2
A
A= $ENV{"HOME"}
Aresult
11
00
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
BranchTrueFalseTotal
if not defined $self->url or $self->url eq "" 0 0 0
Condition0%0/3
not defined $self->url or $self->url eq ""
l!l&&r!l&&!r
000
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 ""
ABresult
1X1
011
000
27 0 ▶ die( 'The url ' . $self->url . " starts with -\n" ) if index( $self->url, q{-} ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($self->url, "-") == 0 0 0 0
28 0 ▶ die( 'The ref ' . $self->ref . " starts with -\n" ) if index( $self->ref, q{-} ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($self->ref, "-") == 0 0 0 0
29 0 return $self;
30 }
31  
32 # The directory of the clone of this URL and ref, which may not exist yet.
33 # @returns InstanceOf["Mojo::File"] the directory
34 # @throws when neither C<$XDG_CACHE_HOME> nor C<$HOME> is set and no L</cache> is given
35 # @example my $clone = $source->clone_dir;
36 0 ▶sub clone_dir ($self) {
Subroutine clone_dir: not called CC=1 SCAR=6.9
Pod documented
37 0 return Mojo::File->new( $self->cache )->child( Digest::SHA::sha1_hex( $self->url . "\n" . $self->ref ) );
38 }
39  
40  
41 0 ▶sub root ($self) {
Subroutine root: not called CC=4 SCAR=30.0
Pod documented
42 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 }
l!l&&r!l&&!r
000
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 }
ABresult
1X1
011
000
43 0 my $dir = $self->clone_dir;
44 0 ▶ if ( $self->offline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->offline) { } 0 0 0
45 0 ▶ die( 'Offline, and there is no cached copy of ' . $self->describe, "\n" ) if !-d $dir->child('.git');
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir->child(".git") 0 0 0
46 }
47 else {
48 0 $self->fetch;
49 }
50 0 $dir;
51 };
52 }
53  
54 # Clones the repository if there is no clone yet, fetches L</ref>, and checks out
55 # what it fetched, discarding any change in the checkout.
56 # @returns InstanceOf["Mojo::File"] the directory of the clone
57 # @throws with what git said when a step fails
58 # @example $source->fetch;
59 0 ▶sub fetch ($self) {
Subroutine fetch: not called CC=2 SCAR=17.9
Pod documented
60 0 my $dir = $self->clone_dir;
61 0 ▶ if ( !-d $dir->child('.git') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir->child(".git")) 0 0 0
62 0 $dir->remove_tree;
63 0 $dir->dirname->make_path;
64 0 git( qw{clone --quiet --no-checkout --}, $self->url, "$dir" );
65 }
66 0 git( '-C', "$dir", qw{fetch --quiet origin}, $self->ref );
67 0 git( '-C', "$dir", qw{checkout --quiet --force --detach FETCH_HEAD} );
68 0 return $dir;
69 }
70  
71  
72 0 ▶sub describe ($self) {
Subroutine describe: not called CC=2 SCAR=17.9
Pod documented
73 0 ▶ return $self->url . ' at ' . $self->ref . ( $self->path ne q{} ? ' (path ' . $self->path . ')' : q{} );
Branch: 1 branch
BranchTrueFalseTotal
$self->path ne '' ? : 0 0 0
74 }
75  
76  
77 # A clone and a fetch need the transports, the credential helpers and the
78 # configuration of the real git, which no CPAN module reproduces.
79 0 ▶sub git (@arguments) {
Subroutine git: not called CC=2 SCAR=17.9
Pod documented
80 0 local $ENV{GIT_TERMINAL_PROMPT} = 0;
81 0 my ( $out, $err ) = ( q{}, q{} );
82 0 IPC::Run3::run3( [ 'git', @arguments ], \undef, \$out, \$err );
83 0 my $status = $?;
84 0 ▶ die( "git @arguments failed: " . ( $err =~ s/\s+\z//r ), "\n" ) if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 0 0 0
85 0 return $out;
86 }
87  
88 __END__
« Conformance/Check/ClaudeSettings.pm ↑ Summary Conformance/Snapshot/Tree.pm »