blib/lib/Git/Hooks/CheckLog.pm

filter: Statementstmt 76.2% 106 / 139 Branchbran 65.7% 46 / 70 Conditioncond 57.6% 30 / 52 MC/DCmcdc 26.9% 7 / 26 Subroutinesub 90.0% 18 / 20 Podpod 0.0% 0 / 10 totaltotal 65.3% 207 / 317 CC 55 SCAR 25.2
CC
55
Cov
70%
title_errors
24.4
spelling_errors
21.2
revert_errors
16.2
CRAP 12.4
« blib/lib/Git/Hooks/CheckCommit.pm ↑ Summary lib/Git/Hooks/Test.pm »
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} //= {}
l!l
229
MC/DC100%1/1
$$config{lc $CFG} //= {}
$$config{lc $CFG}
Truth table100%2/2
A
A= $$config{lc $CFG}
Aresult
11
00
24  
25 31 my $default = $config->{lc $CFG};
26 31 ▶ $default->{'title-required'} //= ['true'];
Condition100%2/2
$default->{"title-required"} //= ["true"]
l!l
130
MC/DC100%1/1
$default->{"title-required"} //= ["true"]
$default->{"title-required"}
Truth table100%2/2
A
A= $default->{"title-required"}
Aresult
11
00
27 31 ▶ $default->{'title-max-width'} //= [50];
Condition100%2/2
$default->{"title-max-width"} //= [50]
l!l
130
MC/DC100%1/1
$default->{"title-max-width"} //= [50]
$default->{"title-max-width"}
Truth table100%2/2
A
A= $default->{"title-max-width"}
Aresult
11
00
28 31 ▶ $default->{'title-period'} //= ['deny'];
Condition100%2/2
$default->{"title-period"} //= ["deny"]
l!l
922
MC/DC100%1/1
$default->{"title-period"} //= ["deny"]
$default->{"title-period"}
Truth table100%2/2
A
A= $default->{"title-period"}
Aresult
11
00
29 31 ▶ $default->{'body-max-width'} //= [72];
Condition100%2/2
$default->{"body-max-width"} //= [72]
l!l
130
MC/DC100%1/1
$default->{"body-max-width"} //= [72]
$default->{"body-max-width"}
Truth table100%2/2
A
A= $default->{"body-max-width"}
Aresult
11
00
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
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 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
BranchTrueFalseTotal
unless $msg 0 29 29
88  
89 29 ▶ return 0 unless $git->get_config_boolean($CFG => 'spelling');
Branch: 1 branch
BranchTrueFalseTotal
unless $git->get_config_boolean($CFG, "spelling") 29 0 29
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 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
BranchTrueFalseTotal
if ($match =~ s/^!\s*//u) { } 8 8 16
116 8 ▶ $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) 2 6 8
Condition60%3/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
620
$git->fault("The commit log $what SHOULD NOT match '\Q$match\E'", {"commit", $id, "option", "match"}) and return 1
!ll
02
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"})
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 8 ▶ $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 5 3 8
Condition60%3/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
530
$git->fault("The commit log $what SHOULD match '\Q$match\E'", {"commit", $id, "option", "match"}) and return 1
!ll
03
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"})
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 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
BranchTrueFalseTotal
if ($git->get_config_boolean($CFG, "deny-merge-revert")) 0 29 29
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 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
BranchTrueFalseTotal
unless (defined $title and length $title) 2 27 29
Condition66%2/3
defined $title and length $title
!ll&&!rl&&r
2027
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
ABresult
0X0
100
111
169 2 ▶ if ($git->get_config_boolean($CFG => 'title-required')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($git->get_config_boolean($CFG, 'title-required')) { } 1 1 2
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
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 27 0 27
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)
l!l
2700
$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 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})
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 27 my $errors = 0;
190  
191 27 ▶ 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")) 26 1 27
192 26 my $tlen = length($title) - 1; # discount the newline
193 26 ▶ $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 25 1 26
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
l!l
2510
$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
010
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 27 ▶ if (my $period = $git->get_config($CFG => 'title-period')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $period = $git->get_config($CFG, "title-period")) 27 0 27
204 27 ▶ if ($period eq 'deny') {
Branch: 3 branches
BranchTrueFalseTotal
if ($period eq 'deny') { } 22 5 27
elsif ($period eq 'require') { } 2 3 5
elsif ($period ne 'allow') { } 1 2 3
205 22 ▶ $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) 3 19 22
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)
!ll
1930
$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
030
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 2 ▶ $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 1 1 2
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
l!l&&r!l&&!r
110
$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
010
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 1 ▶ $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 1 0 1
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
BranchTrueFalseTotal
unless defined $body and length $body 10 19 29
Condition66%2/3
defined $body and length $body
!ll&&!rl&&r
10019
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
ABresult
0X0
100
111
240  
241 19 ▶ 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")) 18 1 19
242 18 ▶ 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)))) 1 17 18
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
BranchTrueFalseTotal
if (@signed_off_by) { } 1 28 29
elsif ($git->get_config_boolean($CFG, 'signed-off-by')) { } 1 27 28
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
BranchTrueFalseTotal
if ($signed_off_by{$person} == 2) 0 1 1
269 0 push @duplicates, $person;
270 }
271 }
272 1 ▶ if (@duplicates) {
Branch: 1 branch
BranchTrueFalseTotal
if (@duplicates) 0 1 1
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
BranchTrueFalseTotal
defined $commit ? : 0 29 29
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__
« blib/lib/Git/Hooks/CheckCommit.pm ↑ Summary lib/Git/Hooks/Test.pm »