utils/prepare-commit-msg-hook

filter: Statementstmt 85.9% 49 / 57 Branchbran 46.1% 12 / 26 Conditioncond 27.2% 6 / 22 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 60.9% 78 / 128 CC 22 SCAR 39.5
CC
22
Cov
64%
main
78.4
get_ticket
2.1
BEGIN
1.0
CRAP 51.9
↑ Summary utils/commit-msg-hook »
1 #!/usr/bin/env perl
2  
3 # Git prepare-commit-msg hook to help create commit messages according to our
4 # standards.
5  
6 2 ▶use v5.26.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings FATAL => qw( recursion );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use experimental "signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use feature "unicode_strings";
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Cwd qw( abs_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use File::Basename qw( dirname );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use lib dirname(abs_path(__FILE__)) . "/lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use GitHook qw( get_current_branch on_main ticket_re );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 $|++;
18  
19 2 my $Ticket_re = ticket_re;
20  
21 2 ▶sub get_ticket () { get_current_branch =~ /^($Ticket_re)/ ? $1 : "GH-XXXXX" }
Subroutine get_ticket: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
get_current_branch() =~ /^($Ticket_re)/u ? : 0 2 2
22  
23 2 ▶sub main () {
Subroutine main: called CC=21 SCAR=43.6
24 2 my ($file, $type) = @ARGV;
25 2 ▶ $type //= $ENV{PRE_COMMIT_COMMIT_MSG_SOURCE} // "";
Condition25%1/4
$type //= $ENV{"PRE_COMMIT_COMMIT_MSG_SOURCE"} // ""
l!l
20
$ENV{"PRE_COMMIT_COMMIT_MSG_SOURCE"} // ""
l!l
00
MC/DC0%0/1
$type //= $ENV{"PRE_COMMIT_COMMIT_MSG_SOURCE"} // ""
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
26  
27 2 ▶ return 0 if $type !~ /^(?:|message|template|merge)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /^(?:|message|template|merge)$/u 0 2 2
28  
29 2 my $main = on_main;
30 2 my $ticket = get_ticket;
31 2 my ($seen_ticket, $seen_scissors);
32  
33 2 local ($^I, @ARGV) = ("", $file);
34 2 ▶ while (my $line = <<>>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = <<>>)) 2 2 4
35 2 chomp $line;
36  
37 2 ▶ if ($type eq "merge") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'merge') { } 0 2 2
38 0 $line =~ s/^(Merge branch ')($Ticket_re).*/$1$2'/;
39 0 ▶ say "" if $. == 2 && $line ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $. == 2 and $line ne "" 0 0 0
Condition0%0/3
$. == 2 and $line ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$. == 2 and $line ne ""
$. == 2 $line ne ""
Truth table0%0/3
A and B
A= $. == 2B= $line ne ""
ABresult
0X0
100
111
40 } else {
41 2 ▶ if (!$main) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($main) 2 0 2
42 2 ▶ if ($. == 1 && $line eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($. == 1 and $line eq "") 0 2 2
Condition33%1/3
$. == 1 and $line eq ""
!ll&&!rl&&r
020
MC/DC0%0/2
$. == 1 and $line eq ""
$. == 1 $line eq ""
Truth table33%1/3
A and B
A= $. == 1B= $line eq ""
ABresult
0X0
100
111
43 0 say "\n\nTicket $ticket\n";
44 0 $seen_ticket = 1;
45 0 next;
46 }
47 2 ▶ if ($. == 3 && !$seen_ticket) {
Branch: 1 branch
BranchTrueFalseTotal
if ($. == 3 and not $seen_ticket) 0 2 2
Condition33%1/3
$. == 3 and not $seen_ticket
!ll&&!rl&&r
200
MC/DC0%0/2
$. == 3 and not $seen_ticket
$. == 3 not $seen_ticket
Truth table33%1/3
A and not(B)
A= $. == 3B= not $seen_ticket
ABresult
0X0
100
111
48 0 $seen_ticket = 1;
49 0 ▶ unless ($line =~ /^Ticket $Ticket_re$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /^Ticket $Ticket_re$/u) 0 0 0
50 0 say "Ticket $ticket\n";
51 }
52 }
53 }
54 2 ▶ $seen_scissors = 1
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "# ------------------------ >8 ------------------------" 0 2 2
55 if $line eq "# ------------------------ >8 ------------------------";
56 }
57  
58 2 say $line;
59  
60 2 ▶ if (eof) {
Branch: 1 branch
BranchTrueFalseTotal
if (eof) 2 0 2
61 2 ▶ say "\nTicket $ticket" if !$main && $type ne "merge" && !$seen_ticket;
Branch: 1 branch
BranchTrueFalseTotal
if not $main and $type ne "merge" and not $seen_ticket 2 0 2
Condition33%2/6
not $main and $type ne "merge" and not $seen_ticket
!ll&&!rl&&r
002
not $main and $type ne "merge"
!ll&&!rl&&r
002
MC/DC0%0/3
not $main and $type ne "merge" and not $seen_ticket
not $main $type ne "merge" not $seen_ticket
Truth table25%1/4
not(A) and B and not(C)
A= not $mainB= $type ne "merge"C= not $seen_ticket
ABCresult
0XX0
10X0
1100
1111
62 2 ▶ say "#\n# *** HINT ***\n",
Branch: 1 branch
BranchTrueFalseTotal
unless $type or $seen_scissors 0 2 2
Condition33%1/3
$type or $seen_scissors
l!l&&r!l&&!r
200
MC/DC0%0/2
$type or $seen_scissors
$type $seen_scissors
Truth table33%1/3
A or B
A= $typeB= $seen_scissors
ABresult
1X1
011
000
63 "# Add the -v option to git commit to see your changes here\n",
64 '# or run "git config --global commit.verbose true".'
65 if !$type && !$seen_scissors;
66 }
67 }
68  
69 0
70 2 }
71  
72 2 exit main
↑ Summary utils/commit-msg-hook »