| 1 | package Git::Hook::PostReceive; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $Git::Hook::PostReceive::VERSION = '0.3'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use feature "switch"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | #ABSTRACT: Parses git commit information in post-receive hook scripts | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | my $self = bless { utf8 => $args{utf8} ? 1 : 0, }, $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | sub read_stdin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_stdin: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | ▶ | my @lines = @_ ? map { split "\n" } @_ : <>; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | my @branches; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | foreach my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | my $payload = $self->run( split /\s+/, $line ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | push @branches, $payload; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | return $payload; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | return wantarray ? @branches : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 22 | ▶ | sub _git_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_git_cmd: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 22 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 22 | my @args = qw(git); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 22 | ▶ | push @args, "--git-dir=" . $self->{git_dir} if $self->{git_dir}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 22 | ▶ | push @args, "--work-tree=" . $self->{work_tree} if $self->{work_tree}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 22 | return @args; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub detect_action { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
detect_action: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my ( $self, $before, $after ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | chomp $before; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | chomp $after; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( $before ne '0000000000000000000000000000000000000000' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $before = qx(@{[ $self->_git_cmd() ]} rev-parse $before); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return { created => $before }; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( $after ne '0000000000000000000000000000000000000000' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $after = qx(@{[ $self->_git_cmd() ]} rev-parse $after); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return { deleted => $after }; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return { pushed => [ $before, $after ] }; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | ▶ | sub get_repo { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_repo: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | ▶ | return $self->{git_dir} if $self->{git_dir}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | ▶ | return $self->{work_tree} if $self->{work_tree}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | return getcwd(); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | my ( $self, $before, $after, $ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | return unless $before and $after and $ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$before and $after and $ref
$before and $after
MC/DC0%0/3
$before and $after and $ref
$before
$after
$ref
Truth table25%1/4
A and B and C
A= $beforeB= $afterC= $ref
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | my ( $created, $deleted ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | ▶ | if ( $before ne '0000000000000000000000000000000000000000' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | $before = qx(@{[ $self->_git_cmd() ]} rev-parse $before); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | chomp $before; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | $created = 1; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | ▶ | if ( $after ne '0000000000000000000000000000000000000000' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 5 | $after = qx(@{[ $self->_git_cmd() ]} rev-parse $after); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 5 | chomp $after; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | $deleted = 1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | before => $before, | |||||||||||||||||||||||||||||||||||||||||
| 95 | after => $after, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | repository => $self->get_repo(), | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ref => $ref, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | created => $created, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | deleted => $deleted, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | commits => [ $self->get_commits( $before, $after ) ] | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # head_commit => ... # ? | ||||||||||||||||||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | sub get_commits { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_commits: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | my ( $self, $before, $after ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | my $log_string; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | ▶ | if ( $before ne '0000000000000000000000000000000000000000' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$before ne "0000000000000000000000000000000000000000" and $after ne "0000000000000000000000000000000000000000"
MC/DC100%2/2
$before ne "0000000000000000000000000000000000000000" and $after ne "0000000000000000000000000000000000000000"
$before ne "0000000000000000000000000000000000000000"
$after ne "0000000000000000000000000000000000000000"
Truth table100%3/3
A and B
A= $before ne "0000000000000000000000000000000000000000"B= $after ne "0000000000000000000000000000000000000000"
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | && $after ne '0000000000000000000000000000000000000000' ) | ||||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | $log_string = qx(@{[ $self->_git_cmd() ]} rev-list $before...$after); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | elsif ( $after ne '0000000000000000000000000000000000000000' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | $log_string = qx(@{[ $self->_git_cmd() ]} rev-list $after); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | ▶ | return () unless $log_string; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 5 | return reverse map { $self->commit_info($_) } split /\n/, $log_string; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | ▶ | sub commit_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit_info: called CC=12 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | my ( $self, $hash ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | my $commit | |||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | = qx{@{[ $self->_git_cmd() ]} show --format=fuller --date=iso --name-status $hash}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 9 | ▶ | $commit = decode( 'utf8', $commit ) if $self->{utf8}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | my @lines = split /\n/, $commit; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | my $info = { | |||||||||||||||||||||||||||||||||||||||||
| 135 | added => [], | ||||||||||||||||||||||||||||||||||||||||||
| 136 | removed => [], | ||||||||||||||||||||||||||||||||||||||||||
| 137 | modified => [] }; | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 9 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 140 | 102 | $_ = $line; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 102 | ▶ | if (m{^commit (.*)$}i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | $info->{id} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | elsif (m{^author:\s+(.*?)\s<(.*?)>}i) { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | $info->{author} = { name => $1, email => $2 }; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | elsif (m{^commit:\s+(.*?)\s<(.*?)>}i) { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | $info->{commiter} = { name => $1, email => $2 }; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | elsif (m{^authordate:\s+(.*)$}i) { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 9 | $info->{timestamp} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 9 | $info->{timestamp} =~ s/ /T/; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 9 | $info->{timestamp} =~ s/ ([+-])(\d\d)(\d\d)/$1$2:$3/; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | elsif (m{^merge: (\w+)\s+(\w+)}i) { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | $info->{merge} = { parent1 => $1, parent2 => $2 }; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | elsif (m{^A\t(.+)}) { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 13 | push @{ $info->{added} }, $1; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | elsif (m{^D\t(.+)}) { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | push @{ $info->{removed} }, $1; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | elsif (m{^M\t(.+)}) { | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 5 | push @{ $info->{modified} }, $1; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | elsif (m{^ (.*)}) { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 17 | $info->{message} .= $1 . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 9 | chomp $info->{message}; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 9 | return $info; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||||||||||||||||