blib/lib/Git/Hooks/CheckLog.pm

filter: Statementstmt 25.1% 35 / 139 Branchbran 4.2% 3 / 70 Conditioncond 0.0% 0 / 52 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 40.0% 8 / 20 Podpod 0.0% 0 / 10 totaltotal 14.5% 46 / 317 CC 55 SCAR 47.6
CC
55
Cov
15%
title_errors
380.0
_setup_config
42.0
spelling_errors
42.0
CRAP 117.0
« blib/lib/Git/Hooks/CheckJira.pm ↑ Summary lib/Git/Repository/Plugin/GitHooks.pm »
1 1 ▶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 1 $Git::Hooks::CheckLog::VERSION = '3.3.1';
6 1 ▶use v5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Log::Any '$log';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Git::Hooks;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Git::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use List::MoreUtils qw/uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 my $CFG = __PACKAGE__ =~ s/.*::/githooks./r;
14  
15 #############
16 # Grok hook configuration, check it and set defaults.
17  
18 sub _setup_config {
19 0 ▶ my ($git) = @_;
Subroutine _setup_config: not called CC=6 SCAR=37.4
20  
21 0 my $config = $git->get_config();
22  
23 0 ▶ $config->{lc $CFG} //= {};
Condition0%0/2
$$config{lc $CFG} //= {}
l!l
00
MC/DC0%0/1
$$config{lc $CFG} //= {}
$$config{lc $CFG}
Truth table0%0/2
A
A= $$config{lc $CFG}
Aresult
11
00
24  
25 0 my $default = $config->{lc $CFG};
26 0 ▶ $default->{'title-required'} //= ['true'];
Condition0%0/2
$default->{"title-required"} //= ["true"]
l!l
00
MC/DC0%0/1
$default->{"title-required"} //= ["true"]
$default->{"title-required"}
Truth table0%0/2
A
A= $default->{"title-required"}
Aresult
11
00
27 0 ▶ $default->{'title-max-width'} //= [50];
Condition0%0/2
$default->{"title-max-width"} //= [50]
l!l
00
MC/DC0%0/1
$default->{"title-max-width"} //= [50]
$default->{"title-max-width"}
Truth table0%0/2
A
A= $default->{"title-max-width"}
Aresult
11
00
28 0 ▶ $default->{'title-period'} //= ['deny'];
Condition0%0/2
$default->{"title-period"} //= ["deny"]
l!l
00
MC/DC0%0/1
$default->{"title-period"} //= ["deny"]
$default->{"title-period"}
Truth table0%0/2
A
A= $default->{"title-period"}
Aresult
11
00
29 0 ▶ $default->{'body-max-width'} //= [72];
Condition0%0/2
$default->{"body-max-width"} //= [72]
l!l
00
MC/DC0%0/1
$default->{"body-max-width"} //= [72]
$default->{"body-max-width"}
Truth table0%0/2
A
A= $default->{"body-max-width"}
Aresult
11
00
30  
31 0 return;
32 }
33  
34 ##########
35  
36 # Return a Text::SpellChecker object or undef.
37  
38 sub _spell_checker {
39 1 ▶ my ($git, $msg) = @_;
Subroutine _spell_checker: called CC=6 SCAR=26.0
40  
41 1 my %extra_options;
42  
43 1 ▶ if (my $lang = $git->get_config($CFG => 'spelling-lang')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lang = $git->get_config($CFG, "spelling-lang")) 0 1 1
44 0 $extra_options{lang} = $lang;
45 }
46  
47 1 ▶ unless (state $tried_to_check) {
Branch: 1 branch
BranchTrueFalseTotal
unless (state $tried_to_check) 1 0 1
48 1 ▶ unless (eval { require Text::SpellChecker; }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Text::SpellChecker } }) 1 0 1
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
BranchTrueFalseTotal
if (not defined eval { do { $checker->next_word } } and $@) 0 0 0
Condition0%0/3
not defined eval { do { $checker->next_word } } and $@
!ll&&!rl&&r
000
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= $@
ABresult
0X0
100
111
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 sub spelling_errors {
85 0 ▶ my ($git, $id, $msg) = @_;
Subroutine spelling_errors: not called CC=6 SCAR=37.4
Pod undocumented
86  
87 0 ▶ return 0 unless $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless $msg 0 0 0
88  
89 0 ▶ return 0 unless $git->get_config_boolean($CFG => 'spelling');
Branch: 1 branch
BranchTrueFalseTotal
unless $git->get_config_boolean($CFG, "spelling") 0 0 0
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
BranchTrueFalseTotal
my $checker = _spell_checker($git, join("\n", &uniq($msg =~ /\b(\p{Cased_Letter}{3,})\b/giu))) or return 1 0 0 0
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
BranchTrueFalseTotal
if defined $suggestions[0] 0 0 0
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 sub _pattern_error {
113 0 ▶ my ($git, $text, $match, $what, $id) = @_;
Subroutine _pattern_error: not called CC=6 SCAR=37.4
114  
115 0 ▶ if ($match =~ s/^!\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match =~ s/^!\s*//u) { } 0 0 0
116 0 ▶ $text !~ /$match/m
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /$match/mu and ($git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {"commit", $id, "option", "match"}) and return 1) 0 0 0
Condition0%0/5
$text =~ /$match/mu && ($git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {'commit', $id, 'option', 'match'}) && (return 1))
!ll&&!rl&&r
000
$git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {"commit", $id, "option", "match"}) and return 1
!ll
00
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 table0%0/3
A && B
A= $text =~ /$match/muB= $git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {"commit", $id, "option", "match"})
ABresult
0X0
100
111
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 0 ▶ $text =~ /$match/m
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /$match/mu or $git->fault("The commit log $what SHOULD match '\Q$match\E'", {"commit", $id, "option", "match"}) and return 1 0 0 0
Condition0%0/5
$text =~ /$match/mu || $git->fault("The commit log $what SHOULD match '\Q$match\E'", {'commit', $id, 'option', 'match'}) && (return 1)
l!l&&r!l&&!r
000
$git->fault("The commit log $what SHOULD match '\Q$match\E'", {"commit", $id, "option", "match"}) and return 1
!ll
00
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 table0%0/3
A || B
A= $text =~ /$match/muB= $git->fault("The commit log $what SHOULD match '\Q$match\E'", {"commit", $id, "option", "match"})
ABresult
1X1
011
000
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 0 return 0;
129 }
130  
131 sub pattern_errors {
132 0 ▶ my ($git, $id, $msg) = @_;
Subroutine pattern_errors: not called CC=2 SCAR=17.9
Pod undocumented
133  
134 0 my $errors = 0;
135  
136 0 foreach my $match ($git->get_config($CFG => 'match')) {
137 0 $errors += _pattern_error($git, $msg, $match, 'message', $id);
138 }
139  
140 0 return $errors;
141 }
142  
143 sub revert_errors {
144 0 ▶ my ($git, $id, $msg) = @_;
Subroutine revert_errors: not called CC=5 SCAR=34.0
Pod undocumented
145  
146 0 ▶ if ($git->get_config_boolean($CFG => 'deny-merge-revert')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($git->get_config_boolean($CFG, "deny-merge-revert")) 0 0 0
147 0 ▶ if ($msg =~ /This reverts commit ([0-9a-f]{40})/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg =~ /This reverts commit ([0-9a-f]{40})/su) 0 0 0
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
BranchTrueFalseTotal
if (my $reverted_commit = eval { do { $git->get_commit($1) } }) 0 0 0
151 0 ▶ if ($reverted_commit->parent() > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverted_commit->parent > 1) 0 0 0
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 0 return 0;
163 }
164  
165 sub title_errors {
166 0 ▶ my ($git, $id, $title) = @_;
Subroutine title_errors: not called CC=19 SCAR=59.4
Pod undocumented
167  
168 0 ▶ unless (defined $title and length $title) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $title and length $title) 0 0 0
Condition0%0/3
defined $title and length $title
!ll&&!rl&&r
000
MC/DC0%0/2
defined $title and length $title
defined $title length $title
Truth table0%0/3
A and B
A= defined $titleB= length $title
ABresult
0X0
100
111
169 0 ▶ if ($git->get_config_boolean($CFG => 'title-required')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($git->get_config_boolean($CFG, 'title-required')) { } 0 0 0
170 0 $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 0 return 1;
176 } else {
177 0 return 0;
178 }
179 }
180  
181 0 ▶ ($title =~ tr/\n/\n/) == 1
Branch: 1 branch
BranchTrueFalseTotal
$title =~ tr/\n// == 1 or $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 0 0 0
Condition0%0/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)
l!l&&r!l&&!r
000
$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
!ll
00
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 table0%0/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})
ABresult
1X1
011
000
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 0 my $errors = 0;
190  
191 0 ▶ if (my $max_width = $git->get_config_integer($CFG => 'title-max-width')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $max_width = $git->get_config_integer($CFG, "title-max-width")) 0 0 0
192 0 my $tlen = length($title) - 1; # discount the newline
193 0 ▶ $tlen <= $max_width
Branch: 1 branch
BranchTrueFalseTotal
$tlen <= $max_width or $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 0 0 0
Condition0%0/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
l!l&&r!l&&!r
000
$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
!ll&&!rl&&r
000
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
ABCresult
1XX1
0111
00X0
0100
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 0 ▶ if (my $period = $git->get_config($CFG => 'title-period')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $period = $git->get_config($CFG, "title-period")) 0 0 0
204 0 ▶ if ($period eq 'deny') {
Branch: 3 branches
BranchTrueFalseTotal
if ($period eq 'deny') { } 0 0 0
elsif ($period eq 'require') { } 0 0 0
elsif ($period ne 'allow') { } 0 0 0
205 0 ▶ $title !~ /\.$/
Branch: 1 branch
BranchTrueFalseTotal
$title =~ /\.$/u and ($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) 0 0 0
Condition0%0/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)
!ll&&!rl&&r
000
$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
!ll&&!rl&&r
000
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
ABCresult
0XX0
10X0
1100
1111
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 0 ▶ $title =~ /\.$/
Branch: 1 branch
BranchTrueFalseTotal
$title =~ /\.$/u or $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 0 0 0
Condition0%0/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
l!l&&r!l&&!r
000
$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
!ll&&!rl&&r
000
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
ABCresult
1XX1
0111
00X0
0100
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 0 ▶ $git->fault(<<"EOS", {commit => $id, option => 'title-period'})
Branch: 1 branch
BranchTrueFalseTotal
$git->fault("Configuration error: invalid value '${period}' for the configuration option.\nThe valid values are 'deny', 'allow', and 'require'.\n", {"commit", $id, "option", "title-period"}) and ++$errors 0 0 0
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 0 foreach my $match ($git->get_config($CFG => 'title-match')) {
230 0 $errors += _pattern_error($git, $title, $match, 'title', $id);
231 }
232  
233 0 return $errors;
234 }
235  
236 sub body_errors {
237 0 ▶ my ($git, $id, $body) = @_;
Subroutine body_errors: not called CC=5 SCAR=34.0
Pod undocumented
238  
239 0 ▶ return 0 unless defined $body && length $body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body and length $body 0 0 0
Condition0%0/3
defined $body and length $body
!ll&&!rl&&r
000
MC/DC0%0/2
defined $body and length $body
defined $body length $body
Truth table0%0/3
A and B
A= defined $bodyB= length $body
ABresult
0X0
100
111
240  
241 0 ▶ if (my $max_width = $git->get_config_integer($CFG => 'body-max-width')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $max_width = $git->get_config_integer($CFG, "body-max-width")) 0 0 0
242 0 ▶ if (my @biggies = grep {/^\S/} grep {length > $max_width} split(/\n/, $body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@biggies) = grep({/^\S/u;} grep({length $_ > $max_width;} split(/\n/u, $body, 0)))) 0 0 0
243 0 $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 0 return 1;
250 }
251 }
252  
253 0 return 0;
254 }
255  
256 sub footer_errors {
257 0 ▶ my ($git, $id, $cmsg) = @_;
Subroutine footer_errors: not called CC=6 SCAR=37.4
Pod undocumented
258  
259 0 my $errors = 0;
260  
261 0 my @signed_off_by = $cmsg->get_footer_values('signed-off-by');
262  
263 0 ▶ if (@signed_off_by) {
Branch: 2 branches
BranchTrueFalseTotal
if (@signed_off_by) { } 0 0 0
elsif ($git->get_config_boolean($CFG, 'signed-off-by')) { } 0 0 0
264 # Check for duplicate Signed-off-by footers
265 0 my (%signed_off_by, @duplicates);
266 0 foreach my $person (@signed_off_by) {
267 0 $signed_off_by{$person} += 1;
268 0 ▶ if ($signed_off_by{$person} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signed_off_by{$person} == 2) 0 0 0
269 0 push @duplicates, $person;
270 }
271 }
272 0 ▶ if (@duplicates) {
Branch: 1 branch
BranchTrueFalseTotal
if (@duplicates) 0 0 0
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 0 $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 0 ++$errors;
286 }
287  
288 0 return $errors;
289 }
290  
291 sub message_errors {
292 0 ▶ my ($git, $commit, $msg) = @_;
Subroutine message_errors: not called CC=2 SCAR=17.9
Pod undocumented
293  
294 # assert(defined $msg)
295  
296 0 ▶ my $id = defined $commit ? $commit->commit : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $commit ? : 0 0 0
297  
298 0 my $cmsg = Git::Message->new($msg);
299  
300 return
301 0 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 sub check_message_file {
310 0 ▶ my ($git, $msg) = @_;
Subroutine check_message_file: not called CC=1 SCAR=6.9
Pod undocumented
311  
312 0 return message_errors($git, undef, $msg);
313 }
314  
315 sub check_ref {
316 0 ▶ my ($git, $ref) = @_;
Subroutine check_ref: not called CC=2 SCAR=17.9
Pod undocumented
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 sub check_patchset {
328 0 ▶ my ($git, $branch, $commit) = @_;
Subroutine check_patchset: not called CC=1 SCAR=6.9
Pod undocumented
329  
330 0 return message_errors($git, $commit, $commit->message);
331 }
332  
333 # Install hooks
334 1 my $options = {config => \&_setup_config};
335  
336 1 GITHOOKS_CHECK_AFFECTED_REFS(\&check_ref, $options);
337 1 GITHOOKS_CHECK_PATCHSET(\&check_patchset, $options);
338 1 GITHOOKS_CHECK_MESSAGE_FILE(\&check_message_file, $options);
339  
340 1 1;
341  
342 __END__
« blib/lib/Git/Hooks/CheckJira.pm ↑ Summary lib/Git/Repository/Plugin/GitHooks.pm »