| 1 | 32 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Git::Hooks::CheckLog; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Git::Hooks plugin to enforce commit log policies | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 32 | $Git::Hooks::CheckLog::VERSION = '4.0.0'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 32 | ▶ | use v5.30.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 32 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 32 | ▶ | use Log::Any '$log'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 32 | ▶ | use Git::Hooks; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 32 | ▶ | use Git::Message; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 32 | ▶ | use List::MoreUtils qw/uniq/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 32 | my $CFG = __PACKAGE__ =~ s/.*::/githooks./r; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | ############# | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # Grok hook configuration, check it and set defaults. | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 31 | ▶ | sub _setup_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_setup_config: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 31 | my ($git) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 31 | my $config = $git->get_config(); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 31 | ▶ | $config->{lc $CFG} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$config{lc $CFG} //= {}
MC/DC100%1/1
$$config{lc $CFG} //= {}
$$config{lc $CFG}
Truth table100%2/2
A
A= $$config{lc $CFG}
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 31 | my $default = $config->{lc $CFG}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 31 | ▶ | $default->{'title-required'} //= ['true']; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$default->{"title-required"} //= ["true"]
MC/DC100%1/1
$default->{"title-required"} //= ["true"]
$default->{"title-required"}
Truth table100%2/2
A
A= $default->{"title-required"}
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 31 | ▶ | $default->{'title-max-width'} //= [50]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$default->{"title-max-width"} //= [50]
MC/DC100%1/1
$default->{"title-max-width"} //= [50]
$default->{"title-max-width"}
Truth table100%2/2
A
A= $default->{"title-max-width"}
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 31 | ▶ | $default->{'title-period'} //= ['deny']; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$default->{"title-period"} //= ["deny"]
MC/DC100%1/1
$default->{"title-period"} //= ["deny"]
$default->{"title-period"}
Truth table100%2/2
A
A= $default->{"title-period"}
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 31 | ▶ | $default->{'body-max-width'} //= [72]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$default->{"body-max-width"} //= [72]
MC/DC100%1/1
$default->{"body-max-width"} //= [72]
$default->{"body-max-width"}
Truth table100%2/2
A
A= $default->{"body-max-width"}
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 31 | return; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | ########## | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # Return a Text::SpellChecker object or undef. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub _spell_checker { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_spell_checker: called CC=6 SCAR=26.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | my ($git, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my %extra_options; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if (my $lang = $git->get_config($CFG => 'spelling-lang')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $extra_options{lang} = $lang; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | unless (state $tried_to_check) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | unless (eval { require Text::SpellChecker; }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | $git->fault(<<'EOS', {option => 'spelling', details => $@}); | |||||||||||||||||||||||||||||||||||||||||
| 50 | I could not load the Text::SpellChecker Perl module. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | I need it to spell check your commit's messages as requested by this | ||||||||||||||||||||||||||||||||||||||||||
| 53 | configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | Please, install the module or disable the option to proceed. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # Text::SpellChecker uses either Text::Hunspell or | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # Text::Aspell to perform the checks. But it doesn't try to | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # load those modules until we invoke its next_word method. So, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # in order to detect errors in those modules we first create a | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # bogus Text::SpellChecker object and force it to spell a word | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # to see if it can go so far. | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my $checker = Text::SpellChecker->new(text => 'a', %extra_options); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (! defined eval { $checker->next_word(); } && $@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined eval {
do {
$checker->next_word
}
} and $@
MC/DC0%0/2
not defined eval {
do {
$checker->next_word
}
} and $@
not defined eval {
do {
$checker->next_word
}
}
$@
Truth table0%0/3
not(A) and B
A= not defined eval {
do {
$checker->next_word
}
}B= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $git->fault(<<'EOS', {option => 'spelling', details => $@}); | |||||||||||||||||||||||||||||||||||||||||
| 71 | There was an error while I tried to spell check your commits using the | ||||||||||||||||||||||||||||||||||||||||||
| 72 | Text::SpellChecker module. If you cannot fix it consider disabling this | ||||||||||||||||||||||||||||||||||||||||||
| 73 | your configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $tried_to_check = 1; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return Text::SpellChecker->new(text => $msg, %extra_options); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 29 | ▶ | sub spelling_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spelling_errors: called CC=6 SCAR=30.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 29 | my ($git, $id, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 29 | ▶ | return 0 unless $msg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 29 | ▶ | return 0 unless $git->get_config_boolean($CFG => 'spelling'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # Check all words comprised of at least three Unicode letters | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $checker = _spell_checker($git, join("\n", uniq($msg =~ /\b(\p{Cased_Letter}{3,})\b/gi))) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | or return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $errors = 0; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | foreach my $badword ($checker->next_word()) { | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my @suggestions = $checker->suggestions($badword); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my %info = (option => 'spelling'); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $info{details} = join("\n ", 'SUGGESTIONS:', @suggestions) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | if defined $suggestions[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $git->fault("The commit $id log message has a misspelled word: '$badword'", \%info); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ++$errors; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return $errors; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | ########## | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # Perform a single pattern check and return the number of errors. | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 16 | ▶ | sub _pattern_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pattern_error: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 16 | my ($git, $text, $match, $what, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 16 | ▶ | if ($match =~ s/^!\s*//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | ▶ | $text !~ /$match/m | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$text =~ /$match/mu && ($git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {'commit', $id, 'option', 'match'}) && (return 1))
$git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {"commit", $id, "option", "match"}) and return 1
MC/DC0%0/2
$text =~ /$match/mu && ($git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {'commit', $id, 'option', 'match'}) && (return 1))
$text =~ /$match/mu
$git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {"commit", $id, "option", "match"})
Truth table33%1/3
A && B
A= $text =~ /$match/muB= $git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {"commit", $id, "option", "match"})
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | or $git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", | ||||||||||||||||||||||||||||||||||||||||||
| 118 | {commit => $id, option => 'match'}) | ||||||||||||||||||||||||||||||||||||||||||
| 119 | and return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | ▶ | $text =~ /$match/m | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$text =~ /$match/mu || $git->fault("The commit log $what SHOULD match '\Q$match\E'", {'commit', $id, 'option', 'match'}) && (return 1)
$git->fault("The commit log $what SHOULD match '\Q$match\E'", {"commit", $id, "option", "match"}) and return 1
MC/DC0%0/2
$text =~ /$match/mu || $git->fault("The commit log $what SHOULD match '\Q$match\E'", {'commit', $id, 'option', 'match'}) && (return 1)
$text =~ /$match/mu
$git->fault("The commit log $what SHOULD match '\Q$match\E'", {"commit", $id, "option", "match"})
Truth table66%2/3
A || B
A= $text =~ /$match/muB= $git->fault("The commit log $what SHOULD match '\Q$match\E'", {"commit", $id, "option", "match"})
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | or $git->fault("The commit log $what SHOULD match '\Q$match\E'", | ||||||||||||||||||||||||||||||||||||||||||
| 124 | {commit => $id, option => 'match'}) | ||||||||||||||||||||||||||||||||||||||||||
| 125 | and return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 11 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 29 | ▶ | sub pattern_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pattern_errors: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 29 | my ($git, $id, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 29 | my $errors = 0; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 29 | foreach my $match ($git->get_config($CFG => 'match')) { | |||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | $errors += _pattern_error($git, $msg, $match, 'message', $id); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 29 | return $errors; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 29 | ▶ | sub revert_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
revert_errors: called CC=5 SCAR=27.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 29 | my ($git, $id, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 29 | ▶ | if ($git->get_config_boolean($CFG => 'deny-merge-revert')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ($msg =~ /This reverts commit ([0-9a-f]{40})/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | # Get the reverted commit in an eval because it may be unreachable | ||||||||||||||||||||||||||||||||||||||||||
| 149 | # now. In this case we simply don't care anymore. | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (my $reverted_commit = eval {$git->get_commit($1)}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ($reverted_commit->parent() > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $git->fault(<<'EOS', {commit => $id, option => 'deny-merge-revert'}); | |||||||||||||||||||||||||||||||||||||||||
| 153 | This commit reverts a merge commit, which is not allowed | ||||||||||||||||||||||||||||||||||||||||||
| 154 | by your configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 29 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 29 | ▶ | sub title_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
title_errors: called CC=19 SCAR=31.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 29 | my ($git, $id, $title) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 29 | ▶ | unless (defined $title and length $title) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $title and length $title
MC/DC50%1/2
defined $title and length $title
defined $title
length $title
Truth table66%2/3
A and B
A= defined $titleB= length $title
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | ▶ | if ($git->get_config_boolean($CFG => 'title-required')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | $git->fault(<<'EOS', {commit => $id, option => 'title-required'}); | |||||||||||||||||||||||||||||||||||||||||
| 171 | This commit log message needs a title line. | ||||||||||||||||||||||||||||||||||||||||||
| 172 | This is required by your configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 173 | Please, amend your commit to add one. | ||||||||||||||||||||||||||||||||||||||||||
| 174 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 27 | ▶ | ($title =~ tr/\n/\n/) == 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$title =~ tr/\n// == 1 || $git->fault("This commit log message title must have just one line.\nPlease amend your commit and edit its log message so that its first line\nis separated from the rest by an empty line.\n", {'commit', $id}) && (return 1)
$git->fault("This commit log message title must have just one line.\nPlease amend your commit and edit its log message so that its first line\nis separated from the rest by an empty line.\n", {"commit", $id}) and return 1
MC/DC0%0/2
$title =~ tr/\n// == 1 || $git->fault("This commit log message title must have just one line.\nPlease amend your commit and edit its log message so that its first line\nis separated from the rest by an empty line.\n", {'commit', $id}) && (return 1)
$title =~ tr/\n// == 1
$git->fault("This commit log message title must have just one line.\nPlease amend your commit and edit its log message so that its first line\nis separated from the rest by an empty line.\n", {"commit", $id})
Truth table33%1/3
A || B
A= $title =~ tr/\n// == 1B= $git->fault("This commit log message title must have just one line.\nPlease amend your commit and edit its log message so that its first line\nis separated from the rest by an empty line.\n", {"commit", $id})
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | or $git->fault(<<'EOS', {commit => $id}) | ||||||||||||||||||||||||||||||||||||||||||
| 183 | This commit log message title must have just one line. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | Please amend your commit and edit its log message so that its first line | ||||||||||||||||||||||||||||||||||||||||||
| 185 | is separated from the rest by an empty line. | ||||||||||||||||||||||||||||||||||||||||||
| 186 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 187 | and return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 27 | my $errors = 0; | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 27 | ▶ | if (my $max_width = $git->get_config_integer($CFG => 'title-max-width')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 26 | my $tlen = length($title) - 1; # discount the newline | |||||||||||||||||||||||||||||||||||||||||
| 193 | 26 | ▶ | $tlen <= $max_width | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$tlen <= $max_width || $git->fault("This commit log message title is too long.\nIt is $tlen characters wide but should be at most $max_width, a limit set by\nyour configuration option.\nPlease, amend your commit to make its title shorter.\n", {'commit', $id, 'option', 'title-max-width'}) && ++$errors
$git->fault("This commit log message title is too long.\nIt is $tlen characters wide but should be at most $max_width, a limit set by\nyour configuration option.\nPlease, amend your commit to make its title shorter.\n", {"commit", $id, "option", "title-max-width"}) and ++$errors
MC/DC0%0/3
$tlen <= $max_width || $git->fault("This commit log message title is too long.\nIt is $tlen characters wide but should be at most $max_width, a limit set by\nyour configuration option.\nPlease, amend your commit to make its title shorter.\n", {'commit', $id, 'option', 'title-max-width'}) && ++$errors
$tlen <= $max_width
$git->fault("This commit log message title is too long.\nIt is $tlen characters wide but should be at most $max_width, a limit set by\nyour configuration option.\nPlease, amend your commit to make its title shorter.\n", {"commit", $id, "option", "title-max-width"})
++$errors
Truth table0%0/4
A || B and C
A= $tlen <= $max_widthB= $git->fault("This commit log message title is too long.\nIt is $tlen characters wide but should be at most $max_width, a limit set by\nyour configuration option.\nPlease, amend your commit to make its title shorter.\n", {"commit", $id, "option", "title-max-width"})C= ++$errors
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | or $git->fault(<<"EOS", {commit => $id, option => 'title-max-width'}) | ||||||||||||||||||||||||||||||||||||||||||
| 195 | This commit log message title is too long. | ||||||||||||||||||||||||||||||||||||||||||
| 196 | It is $tlen characters wide but should be at most $max_width, a limit set by | ||||||||||||||||||||||||||||||||||||||||||
| 197 | your configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | Please, amend your commit to make its title shorter. | ||||||||||||||||||||||||||||||||||||||||||
| 199 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 200 | and ++$errors; | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 27 | ▶ | if (my $period = $git->get_config($CFG => 'title-period')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 27 | ▶ | if ($period eq 'deny') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 22 | ▶ | $title !~ /\.$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$title =~ /\.$/u && ($git->fault("This commit log message title SHOULD NOT end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to remove the period.\n", {'commit', $id, 'option', 'title-period'}) && ++$errors)
$git->fault("This commit log message title SHOULD NOT end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to remove the period.\n", {"commit", $id, "option", "title-period"}) and ++$errors
MC/DC0%0/3
$title =~ /\.$/u && ($git->fault("This commit log message title SHOULD NOT end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to remove the period.\n", {'commit', $id, 'option', 'title-period'}) && ++$errors)
$title =~ /\.$/u
$git->fault("This commit log message title SHOULD NOT end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to remove the period.\n", {"commit", $id, "option", "title-period"})
++$errors
Truth table0%0/4
A && B and C
A= $title =~ /\.$/uB= $git->fault("This commit log message title SHOULD NOT end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to remove the period.\n", {"commit", $id, "option", "title-period"})C= ++$errors
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | or $git->fault(<<'EOS', {commit => $id, option => 'title-period'}) | ||||||||||||||||||||||||||||||||||||||||||
| 207 | This commit log message title SHOULD NOT end in a period. | ||||||||||||||||||||||||||||||||||||||||||
| 208 | This is required by your configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 209 | Please, amend your commit to remove the period. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 211 | and ++$errors; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | } elsif ($period eq 'require') { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | ▶ | $title =~ /\.$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$title =~ /\.$/u || $git->fault("This commit log message title SHOULD end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to add the period.\n", {'commit', $id, 'option', 'title-period'}) && ++$errors
$git->fault("This commit log message title SHOULD end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to add the period.\n", {"commit", $id, "option", "title-period"}) and ++$errors
MC/DC0%0/3
$title =~ /\.$/u || $git->fault("This commit log message title SHOULD end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to add the period.\n", {'commit', $id, 'option', 'title-period'}) && ++$errors
$title =~ /\.$/u
$git->fault("This commit log message title SHOULD end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to add the period.\n", {"commit", $id, "option", "title-period"})
++$errors
Truth table0%0/4
A || B and C
A= $title =~ /\.$/uB= $git->fault("This commit log message title SHOULD end in a period.\nThis is required by your configuration option.\nPlease, amend your commit to add the period.\n", {"commit", $id, "option", "title-period"})C= ++$errors
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | or $git->fault(<<'EOS', {commit => $id, option => 'title-period'}) | ||||||||||||||||||||||||||||||||||||||||||
| 215 | This commit log message title SHOULD end in a period. | ||||||||||||||||||||||||||||||||||||||||||
| 216 | This is required by your configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 217 | Please, amend your commit to add the period. | ||||||||||||||||||||||||||||||||||||||||||
| 218 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 219 | and ++$errors; | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } elsif ($period ne 'allow') { | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | $git->fault(<<"EOS", {commit => $id, option => 'title-period'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | Configuration error: invalid value '$period' for the configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 223 | The valid values are 'deny', 'allow', and 'require'. | ||||||||||||||||||||||||||||||||||||||||||
| 224 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 225 | and ++$errors; | ||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 27 | foreach my $match ($git->get_config($CFG => 'title-match')) { | |||||||||||||||||||||||||||||||||||||||||
| 230 | 10 | $errors += _pattern_error($git, $title, $match, 'title', $id); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 27 | return $errors; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 29 | ▶ | sub body_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body_errors: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 29 | my ($git, $id, $body) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 29 | ▶ | return 0 unless defined $body && length $body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $body and length $body
MC/DC50%1/2
defined $body and length $body
defined $body
length $body
Truth table66%2/3
A and B
A= defined $bodyB= length $body
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 19 | ▶ | if (my $max_width = $git->get_config_integer($CFG => 'body-max-width')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 18 | ▶ | if (my @biggies = grep {/^\S/} grep {length > $max_width} split(/\n/, $body)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | $git->fault(<<"EOS", {commit => $id, option => 'body-max-width', details => join("\n", @biggies)}); | |||||||||||||||||||||||||||||||||||||||||
| 244 | This commit log body has lines that are too long. | ||||||||||||||||||||||||||||||||||||||||||
| 245 | The configuration option limits body lines to $max_width characters. | ||||||||||||||||||||||||||||||||||||||||||
| 246 | But the following lines exceed it. | ||||||||||||||||||||||||||||||||||||||||||
| 247 | Please, amend your commit to make its lines shorter. | ||||||||||||||||||||||||||||||||||||||||||
| 248 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 18 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 29 | ▶ | sub footer_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
footer_errors: called CC=6 SCAR=18.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 29 | my ($git, $id, $cmsg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 29 | my $errors = 0; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 29 | my @signed_off_by = $cmsg->get_footer_values('signed-off-by'); | |||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 29 | ▶ | if (@signed_off_by) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | # Check for duplicate Signed-off-by footers | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | my (%signed_off_by, @duplicates); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | foreach my $person (@signed_off_by) { | |||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | $signed_off_by{$person} += 1; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | if ($signed_off_by{$person} == 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | push @duplicates, $person; | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | if (@duplicates) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $git->fault(<<'EOS', {commit => $id, details => join("\n", sort @duplicates)}); | |||||||||||||||||||||||||||||||||||||||||
| 274 | This commit have duplicate Signed-off-by footers. | ||||||||||||||||||||||||||||||||||||||||||
| 275 | Please, amend it to remove the duplicates: | ||||||||||||||||||||||||||||||||||||||||||
| 276 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ++$errors; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | } elsif ($git->get_config_boolean($CFG => 'signed-off-by')) { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | $git->fault(<<'EOS', {commit => $id, option => 'signed-off-by'}); | |||||||||||||||||||||||||||||||||||||||||
| 281 | This commit must have a Signed-off-by footer. | ||||||||||||||||||||||||||||||||||||||||||
| 282 | This is required by your configuration option. | ||||||||||||||||||||||||||||||||||||||||||
| 283 | Please, amend your commit to add it. | ||||||||||||||||||||||||||||||||||||||||||
| 284 | EOS | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | ++$errors; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 29 | return $errors; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 29 | ▶ | sub message_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message_errors: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 29 | my ($git, $commit, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | # assert(defined $msg) | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 29 | ▶ | my $id = defined $commit ? $commit->commit : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 29 | my $cmsg = Git::Message->new($msg); | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | return | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 29 | spelling_errors($git, $id, $msg) + | |||||||||||||||||||||||||||||||||||||||||
| 302 | pattern_errors($git, $id, $msg) + | ||||||||||||||||||||||||||||||||||||||||||
| 303 | revert_errors($git, $id, $msg) + | ||||||||||||||||||||||||||||||||||||||||||
| 304 | title_errors($git, $id, $cmsg->title) + | ||||||||||||||||||||||||||||||||||||||||||
| 305 | body_errors($git, $id, $cmsg->body) + | ||||||||||||||||||||||||||||||||||||||||||
| 306 | footer_errors($git, $id, $cmsg); | ||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 29 | ▶ | sub check_message_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_message_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 29 | my ($git, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 29 | return message_errors($git, undef, $msg); | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | sub check_ref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_ref: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my ($git, $ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $errors = 0; | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | foreach my $commit ($git->get_affected_ref_commits($ref)) { | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $errors += message_errors($git, $commit, $commit->message); | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | return $errors; | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub check_patchset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_patchset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my ($git, $branch, $commit) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return message_errors($git, $commit, $commit->message); | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | # Install hooks | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 32 | my $options = {config => \&_setup_config}; | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 32 | GITHOOKS_CHECK_AFFECTED_REFS(\&check_ref, $options); | |||||||||||||||||||||||||||||||||||||||||
| 337 | 32 | GITHOOKS_CHECK_PATCHSET(\&check_patchset, $options); | |||||||||||||||||||||||||||||||||||||||||
| 338 | 32 | GITHOOKS_CHECK_MESSAGE_FILE(\&check_message_file, $options); | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 32 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | __END__ | ||||||||||||||||||||||||||||||||||||||||||