| 1 | package Code::TidyAll::Git::Util; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use File::pushd qw(pushd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use IPC::System::Simple qw(capturex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use List::SomeUtils qw(uniq); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use Path::Tiny qw(path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 17 | our $VERSION = '0.85'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 17 | our @EXPORT_OK = qw(git_files_to_commit git_modified_files); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 30 | ▶ | sub git_files_to_commit { | ||||||||||||||||||||||||||
|
Subroutine
git_files_to_commit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 30 | my ($dir) = @_; | |||||||||||||||||||||||||||
| 19 | 30 | return _relevant_files_from_status( $dir, 1 ); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | sub git_modified_files { | ||||||||||||||||||||||||||
|
Subroutine
git_modified_files: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 3 | my ($dir) = @_; | |||||||||||||||||||||||||||
| 24 | 3 | return _relevant_files_from_status( $dir, 0 ); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 33 | ▶ | sub _relevant_files_from_status { | ||||||||||||||||||||||||||
|
Subroutine
_relevant_files_from_status: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 33 | my ( $dir, $index_only ) = @_; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 33 | $dir = path($dir); | |||||||||||||||||||||||||||
| 31 | 33 | my $pushed = pushd( $dir->absolute ); | |||||||||||||||||||||||||||
| 32 | 33 | my $status = capturex(qw( git status --porcelain -z -uno )); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 33 | ▶ | return unless $status; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 27 | return map { $dir->child($_) } _parse_status( $status, $index_only ); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 28 | ▶ | sub _parse_status { | ||||||||||||||||||||||||||
|
Subroutine
_parse_status: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 40 | 28 | my ( $status, $index_only ) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 28 | local $_ = $status; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # There can't possibly be more records than nuls plus one, so we use this | ||||||||||||||||||||||||||||
| 45 | # as an upper bound on passes. | ||||||||||||||||||||||||||||
| 46 | 28 | my $times = tr/\0/\0/; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 28 | my @files; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 28 | for my $i ( 0 .. $times ) { | |||||||||||||||||||||||||||
| 51 | 71 | ▶ | last if /\G\Z/gc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 43 | /\G(..) /g; | |||||||||||||||||||||||||||
| 54 | 43 | my $mode = $1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 43 | /\G([^\0]+)\0/g; | |||||||||||||||||||||||||||
| 57 | 43 | my $name = $1; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # on renames, parse but throw away the "renamed from" filename | ||||||||||||||||||||||||||||
| 60 | 43 | ▶ | if ( $mode =~ /[CR]/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 2 | /\G([^\0]+)\0/g; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # deletions and renames don't cause tidying | ||||||||||||||||||||||||||||
| 65 | 43 | ▶ | next unless $mode =~ /[MA]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 40 | ▶ | next if $index_only && $mode =~ /^ /; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$index_only and $mode =~ /^ /
MC/DC100%2/2
$index_only and $mode =~ /^ /
$index_only
$mode =~ /^ /
Truth table100%3/3
A and B
A= $index_onlyB= $mode =~ /^ /
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 28 | push @files, $name; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 28 | return @files; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 17 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # ABSTRACT: Utilities for the git hook classes | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||