| 1 | package Test::Git; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 15 | $Test::Git::VERSION = '1.326'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 15 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 15 | ▶ | use Test::Builder; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Git::Repository; # 1.15 | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use File::Temp qw( tempdir ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 15 | ▶ | use File::Spec::Functions qw( catdir ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Git::Version::Compare qw( cmp_git ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use Cwd qw( cwd ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 15 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | our @ISA = qw( Exporter ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 15 | our @EXPORT = qw( has_git test_repository ); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 15 | my $Test = Test::Builder->new(); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub has_git { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_git: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ( $version, @options ) = ( ( grep !ref, @_ )[0], grep ref, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | carp sprintf 'has_git() is obsolete, write `use Test::Requires::Git; test_requires_git%s;` instead', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | $version ? " '$version'" : ''; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # check some git is present | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $Test->skip_all('Default git binary not found in PATH') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | if !Git::Repository::Command::_is_git('git'); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # check it's at least some minimum version | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $git_version = Git::Repository->version(@options); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $Test->skip_all( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$version and "Git::Repository"->version_lt($version, @options)
MC/DC0%0/2
$version and "Git::Repository"->version_lt($version, @options)
$version
"Git::Repository"->version_lt($version, @options)
Truth table0%0/3
A and B
A= $versionB= "Git::Repository"->version_lt($version, @options)
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | "Test script requires git >= $version (this is only $git_version)") | ||||||||||||||||||||||||||||||||||||||||||
| 33 | if $version && Git::Repository->version_lt( $version, @options ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 13 | ▶ | sub test_repository { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
test_repository: called CC=14 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 13 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | croak "Can't use both 'init' and 'clone' parameters" | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | ▶ | if exists $args{init} && exists $args{clone}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $args{"init"} and exists $args{"clone"}
MC/DC0%0/2
exists $args{"init"} and exists $args{"clone"}
exists $args{"init"}
exists $args{"clone"}
Truth table66%2/3
A and B
A= exists $args{"init"}B= exists $args{"clone"}
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # setup some default values | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 13 | ▶ | my $temp = $args{temp} || [ CLEANUP => 1 ]; # File::Temp options | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'temp'} || ['CLEANUP', 1]
MC/DC0%0/1
$args{'temp'} || ['CLEANUP', 1]
$args{'temp'}
Truth table50%1/2
A
A= $args{'temp'}
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | ▶ | my $init = $args{init} || []; # git init options | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'init'} || []
MC/DC100%1/1
$args{'init'} || []
$args{'init'}
Truth table100%2/2
A
A= $args{'init'}
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 13 | ▶ | my $opts = $args{git} || {}; # Git::Repository options | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'git'} || {}
MC/DC100%1/1
$args{'git'} || {}
$args{'git'}
Truth table100%2/2
A
A= $args{'git'}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 13 | my $safe = { %$opts, fatal => [] }; # ignore 'fatal' settings | |||||||||||||||||||||||||||||||||||||||||
| 47 | 13 | my $clone = $args{clone}; # git clone options | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # version check | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 13 | my $bad_version; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 13 | my $git_version = Git::Repository->version($safe); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 13 | ▶ | if ($clone) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
&cmp_git($git_version, "1.6.2.rc0") < 0 or &cmp_git("1.7.0.rc1", $git_version) <= 0 and &cmp_git($git_version, "1.7.0.2") <= 0
&cmp_git("1.7.0.rc1", $git_version) <= 0 and &cmp_git($git_version, "1.7.0.2") <= 0
MC/DC0%0/3
&cmp_git($git_version, "1.6.2.rc0") < 0 or &cmp_git("1.7.0.rc1", $git_version) <= 0 and &cmp_git($git_version, "1.7.0.2") <= 0
&cmp_git($git_version, "1.6.2.rc0") < 0
&cmp_git("1.7.0.rc1", $git_version) <= 0
&cmp_git($git_version, "1.7.0.2") <= 0
Truth table25%1/4
A or B and C
A= &cmp_git($git_version, "1.6.2.rc0") < 0B= &cmp_git("1.7.0.rc1", $git_version) <= 0C= &cmp_git($git_version, "1.7.0.2") <= 0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | cmp_git( $git_version, '1.6.2.rc0' ) < 0 | ||||||||||||||||||||||||||||||||||||||||||
| 55 | || ( cmp_git( '1.7.0.rc1', $git_version ) <= 0 | ||||||||||||||||||||||||||||||||||||||||||
| 56 | && cmp_git( $git_version, '1.7.0.2' ) <= 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $bad_version = "test_repository( clone => ... ) requires git >= 1.6.2.rc0 and 1.7.0.rc1 < git < 1.7.0.2 (this is $git_version)"; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | elsif ( cmp_git( $git_version, '1.4.0' ) <= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $bad_version = "test_repository( init => ... ) requires git >= 1.4.0 (this is only $git_version)"; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | ▶ | croak $bad_version if $bad_version; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # create a temporary directory to host our repository | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 13 | my $dir = tempdir(@$temp); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | my $cwd = { cwd => $dir }; # option to chdir there | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # create the git repository there | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | ▶ | my $init_cmd = Git::Repository->version_lt('1.5.0.rc1') ? 'init-db' : 'init'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | ▶ | my @cmd = $clone ? ( clone => @$clone, $dir ) : ( $init_cmd => @$init, $cwd ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 13 | Git::Repository->run( @cmd, $safe ); | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # create the Git::Repository object | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 13 | my $gitdir = Git::Repository->run( qw( rev-parse --git-dir ), $cwd ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 13 | return Git::Repository->new( git_dir => catdir( $dir, $gitdir ), $opts ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||||||||||||||||