| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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"} // ""
$ENV{"PRE_COMMIT_COMMIT_MSG_SOURCE"} // ""
MC/DC0%0/1
$type //= $ENV{"PRE_COMMIT_COMMIT_MSG_SOURCE"} // ""
$type
Truth table50%1/2
A
A= $type
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | return 0 if $type !~ /^(?:|message|template|merge)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | if ($type eq "merge") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $line =~ s/^(Merge branch ')($Ticket_re).*/$1$2'/; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | say "" if $. == 2 && $line ne ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$. == 2 and $line ne ""
MC/DC0%0/2
$. == 2 and $line ne ""
$. == 2
$line ne ""
Truth table0%0/3
A and B
A= $. == 2B= $line ne ""
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | if (!$main) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | if ($. == 1 && $line eq "") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$. == 1 and $line eq ""
MC/DC0%0/2
$. == 1 and $line eq ""
$. == 1
$line eq ""
Truth table33%1/3
A and B
A= $. == 1B= $line eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$. == 3 and not $seen_ticket
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
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $seen_ticket = 1; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | unless ($line =~ /^Ticket $Ticket_re$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | say "Ticket $ticket\n"; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | $seen_scissors = 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | if $line eq "# ------------------------ >8 ------------------------"; | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | say $line; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | if (eof) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | ▶ | say "\nTicket $ticket" if !$main && $type ne "merge" && !$seen_ticket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not $main and $type ne "merge" and not $seen_ticket
not $main and $type ne "merge"
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
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | say "#\n# *** HINT ***\n", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type or $seen_scissors
MC/DC0%0/2
$type or $seen_scissors
$type
$seen_scissors
Truth table33%1/3
A or B
A= $typeB= $seen_scissors
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||