| 1 | package Dist::Conformance::Check::GitHooks 0.005; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: The git hooks are tracked, match their templates, and are installed | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.040; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use re '/aasx'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Mojo::Base 'Dist::Conformance::Check', -signatures; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Dist::Conformance::Schema(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Dist::Conformance::Snapshot(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub config_schema ($) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | required => [qw{directory hooks}], | |||||||||||||||||||||||||||||||||||||||||
| 17 | properties => { | ||||||||||||||||||||||||||||||||||||||||||
| 18 | directory => $Dist::Conformance::Schema::PATH, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | hooks => { type => 'object', additionalProperties => $Dist::Conformance::Schema::PATH }, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | differ => { %$Dist::Conformance::Schema::STATUS, default => 'info' }, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | replace => { type => 'boolean', default => 0 }, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | install => { type => 'boolean', default => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub hook_path ( $self, $name ) { return $self->config->{directory} . "/$name" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hook_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub check ( $self, $snapshot ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $hooks = $self->config->{hooks}; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my @names = sort keys %$hooks; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my @missing = $self->missing( $snapshot, map { $self->hook_path($_) } @names ); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return ( 'fail', 'missing: ' . join ', ', @missing ) if @missing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my @differ = grep { $snapshot->sha( $self->hook_path($_) ) ne Dist::Conformance::Snapshot::blob_sha( ( $self->template( $hooks->{$_} ) )[0] ) } @names; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return ( $self->config->{differ}, 'customized or outdated: ' . join ', ', map { $self->hook_path($_) } @differ ) if @differ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return ( 'pass', 'match the templates' ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub update ( $self, $update ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ( $hooks, $replace, $install ) = @{ $self->config }{qw{hooks replace install}}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $snapshot = $update->snapshot; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | for my $name ( sort keys %$hooks ) { | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $path = $self->hook_path($name); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($text) = $self->template( $hooks->{$name} ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $have = $snapshot->content($path); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( !defined $have || ( $replace && $have ne $text ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $have or $replace and $have ne $text
$replace and $have ne $text
MC/DC0%0/3
not defined $have or $replace and $have ne $text
not defined $have
$replace
$have ne $text
Truth table0%0/4
not(A) or B and C
A= not defined $haveB= $replaceC= $have ne $text
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $have = $text if $self->write_template( $update, $path, $hooks->{$name}, oct 755 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $update->install_hook( $name, $have ) if $install && defined $have; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$install and defined $have
MC/DC0%0/2
$install and defined $have
$install
defined $have
Truth table0%0/3
A and B
A= $installB= defined $have
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||||||||||||||||