line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Git; |
2
|
|
|
|
|
|
|
$Test::Git::VERSION = '1.324'; |
3
|
14
|
|
|
14
|
|
958263
|
use strict; |
|
14
|
|
|
|
|
446
|
|
|
14
|
|
|
|
|
554
|
|
4
|
14
|
|
|
14
|
|
108
|
use warnings; |
|
14
|
|
|
|
|
58
|
|
|
14
|
|
|
|
|
733
|
|
5
|
|
|
|
|
|
|
|
6
|
14
|
|
|
14
|
|
94
|
use Exporter; |
|
14
|
|
|
|
|
56
|
|
|
14
|
|
|
|
|
850
|
|
7
|
14
|
|
|
14
|
|
87
|
use Test::Builder; |
|
14
|
|
|
|
|
52
|
|
|
14
|
|
|
|
|
412
|
|
8
|
14
|
|
|
14
|
|
6421
|
use Git::Repository; # 1.15 |
|
14
|
|
|
|
|
37
|
|
|
14
|
|
|
|
|
56
|
|
9
|
14
|
|
|
14
|
|
9299
|
use File::Temp qw( tempdir ); |
|
14
|
|
|
|
|
187181
|
|
|
14
|
|
|
|
|
856
|
|
10
|
14
|
|
|
14
|
|
5554
|
use File::Spec::Functions qw( catdir ); |
|
14
|
|
|
|
|
11077
|
|
|
14
|
|
|
|
|
829
|
|
11
|
14
|
|
|
14
|
|
88
|
use Git::Version::Compare qw( cmp_git ); |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
607
|
|
12
|
14
|
|
|
14
|
|
76
|
use Cwd qw( cwd ); |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
554
|
|
13
|
14
|
|
|
14
|
|
76
|
use Carp; |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
7179
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
16
|
|
|
|
|
|
|
our @EXPORT = qw( has_git test_repository ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $Test = Test::Builder->new(); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub has_git { |
21
|
0
|
|
|
0
|
1
|
0
|
my ( $version, @options ) = ( ( grep !ref, @_ )[0], grep ref, @_ ); |
22
|
0
|
0
|
|
|
|
0
|
carp sprintf 'has_git() is obsolete, write `use Test::Requires::Git; test_requires_git%s;` instead', |
23
|
|
|
|
|
|
|
$version ? " '$version'" : ''; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# check some git is present |
26
|
0
|
0
|
|
|
|
0
|
$Test->skip_all('Default git binary not found in PATH') |
27
|
|
|
|
|
|
|
if !Git::Repository::Command::_is_git('git'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# check it's at least some minimum version |
30
|
0
|
|
|
|
|
0
|
my $git_version = Git::Repository->version(@options); |
31
|
0
|
0
|
0
|
|
|
0
|
$Test->skip_all( |
32
|
|
|
|
|
|
|
"Test script requires git >= $version (this is only $git_version)") |
33
|
|
|
|
|
|
|
if $version && Git::Repository->version_lt( $version, @options ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub test_repository { |
37
|
13
|
|
|
13
|
1
|
41187
|
my %args = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
croak "Can't use both 'init' and 'clone' parameters" |
40
|
13
|
0
|
33
|
|
|
124
|
if exists $args{init} && exists $args{clone}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# setup some default values |
43
|
13
|
|
50
|
|
|
297
|
my $temp = $args{temp} || [ CLEANUP => 1 ]; # File::Temp options |
44
|
13
|
|
50
|
|
|
181
|
my $init = $args{init} || []; # git init options |
45
|
13
|
|
100
|
|
|
178
|
my $opts = $args{git} || {}; # Git::Repository options |
46
|
13
|
|
|
|
|
110
|
my $safe = { %$opts, fatal => [] }; # ignore 'fatal' settings |
47
|
13
|
|
|
|
|
48
|
my $clone = $args{clone}; # git clone options |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# version check |
50
|
13
|
|
|
|
|
32
|
my $bad_version; |
51
|
13
|
|
|
|
|
262
|
my $git_version = Git::Repository->version($safe); |
52
|
13
|
100
|
|
|
|
893
|
if ($clone) { |
|
|
50
|
|
|
|
|
|
53
|
2
|
50
|
33
|
|
|
36
|
if ( |
|
|
|
33
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
0
|
$bad_version = "test_repository( init => ... ) requires git >= 1.4.0 (this is only $git_version)"; |
64
|
|
|
|
|
|
|
} |
65
|
13
|
50
|
|
|
|
1021
|
croak $bad_version if $bad_version; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# create a temporary directory to host our repository |
68
|
13
|
|
|
|
|
269
|
my $dir = tempdir(@$temp); |
69
|
13
|
|
|
|
|
9450
|
my $cwd = { cwd => $dir }; # option to chdir there |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# create the git repository there |
72
|
13
|
50
|
|
|
|
927
|
unshift @$init, |
73
|
|
|
|
|
|
|
Git::Repository->version_lt('1.5.0.rc1') ? 'init-db' : 'init'; |
74
|
13
|
100
|
|
|
|
3243
|
my @cmd = $clone ? ( clone => @$clone, $dir ) : ( @$init, $cwd ); |
75
|
13
|
|
|
|
|
158
|
Git::Repository->run( @cmd, $safe ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# create the Git::Repository object |
78
|
13
|
|
|
|
|
613
|
my $gitdir = Git::Repository->run( qw( rev-parse --git-dir ), $cwd ); |
79
|
13
|
|
|
|
|
775
|
return Git::Repository->new( git_dir => catdir( $dir, $gitdir ), $opts ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |