1Test::Git(3) User Contributed Perl Documentation Test::Git(3)
2
3
4
6 Test::Git - Helper functions for test scripts using Git
7
9 use Test::More;
10 use Test::Git;
11
12 # check there is a git binary available, or skip all
13 has_git();
14
15 # check there is a minimum version of git available, or skip all
16 has_git( '1.6.5' );
17
18 # check the git we want to test has a minimum version, or skip all
19 has_git( '1.6.5', { git => '/path/to/alternative/git' } );
20
21 # normal plan
22 plan tests => 2;
23
24 # create a new, empty repository in a temporary location
25 # and return a Git::Repository object
26 my $r = test_repository();
27
28 # clone an existing repository in a temporary location
29 # and return a Git::Repository object
30 my $c = test_repository( clone => [ $url ] );
31
32 # run some tests on the repository
33 ...
34
36 Test::Git provides a number of helpful functions when running test
37 scripts that require the creation and management of a Git repository.
38
40 has_git
41 has_git( $version, \%options );
42
43 Checks if there is a git binary available, or skips all tests.
44
45 If the optional $version argument is provided, also checks if the
46 available git binary has a version greater or equal to $version.
47
48 This function also accepts an option hash of the same kind as those
49 accepted by Git::Repository and Git::Repository::Command.
50
51 This function must be called before plan(), as it performs a skip_all
52 if requirements are not met.
53
54 "has_git" is now obsolete and will print a warning when used. The
55 "test_requires_git" function provided by the Test::Requires::Git module
56 is a much more flexible replacement.
57
58 "has_git" will be removed in a future release.
59
60 test_repository
61 test_repository( %options );
62
63 Creates a new empty git repository in a temporary location, and returns
64 a Git::Repository object pointing to it.
65
66 This function takes options as a hash. Each key will influence a
67 different part of the creation process.
68
69 The keys are:
70
71 temp
72 Array reference containing parameters to File::Temp "tempdir"
73 function.
74
75 Default: "<[ CLEANUP =" 1 ]>>
76
77 init
78 Array reference containing parameters to "git init". Must not
79 contain the target directory parameter, which is provided by
80 test_repository() (via File::Temp).
81
82 Default: "[]"
83
84 The "init" option is only supported with Git versions higher or
85 equal to 1.6.2.rc0.
86
87 clone
88 Array reference containing parameters to "git clone". Must not
89 contain the target directory parameter, which is provided by
90 test_repository() (via File::Temp).
91
92 Note that "clone" and "init" are mutually exclusive and that
93 test_repository() will croak if both are provided. This option has
94 no default value, since at least a Git URL must be provided to the
95 "clone" option.
96
97 The "clone" option is only supported with Git versions higher or
98 equal to 1.6.2.rc0.
99
100 git Hash reference containing options for Git::Repository.
101
102 Default: "{}"
103
104 This call is the equivalent of the default call with no options:
105
106 test_repository(
107 temp => [ CLEANUP => 1 ], # File::Temp::tempdir options
108 init => [], # git init options
109 git => {}, # Git::Repository options
110 );
111
112 To create a bare repository:
113
114 test_repository( init => [ '--bare' ] );
115
116 To leave the repository in its location after the end of the test:
117
118 test_repository( temp => [ CLEANUP => 0 ] );
119
120 Note that since test_repository() uses "git init" to create the test
121 repository, it requires at least Git version "1.5.0.rc1".
122
124 Philippe Bruhat (BooK) <book@cpan.org>
125
127 The "clone" option and capability of test_repository() owes a lot to
128 Nathan Nutter (NNUTTER), who wanted to be able to clone into a test
129 repository.
130
132 Test::Requires::Git.
133
135 Copyright 2010-2016 Philippe Bruhat (BooK), all rights reserved.
136
138 This program is free software; you can redistribute it and/or modify it
139 under the same terms as Perl itself.
140
141
142
143perl v5.36.0 2023-01-20 Test::Git(3)