Test::Git(3pm)
π Test::Git(3pm) π
Okay bestie, this is the manual page for Test::Git(3pm) β aka the little helper squad for test scripts that need to make and manage a Git repository. Itβs giving βtest setup but make it cute.β π
πΈ NAME πΈ
Test::Git β Helper functions for test scripts using Git
π¦ SYNOPSIS π¦
use Test::More;
use Test::Git;
# check there is a git binary available, or skip all
has_git();
# check there is a minimum version of git available, or skip all
has_git( '1.6.5' );
# check the git we want to test has a minimum version, or skip all
has_git( '1.6.5', { git => '/path/to/alternative/git' } );
# normal plan
plan tests => 2;
# create a new, empty repository in a temporary location
# and return a Git::Repository object
my $r = test_repository();
# clone an existing repository in a temporary location
# and return a Git::Repository object
my $c = test_repository( clone => [ $url ] );
# run some tests on the repository
...
π DESCRIPTION π
Test::Git provides a number of helpful functions when running test scripts that require the creation and management of a Git repository. Literally your test-suite bestie when Git repos need to appear out of thin air. β¨
π EXPORTED FUNCTIONS π
π has_git π
has_git( $version, \%options );
Checks if there is a git binary available, or skips all tests. No git? No problem β we skip, bestie.
If the optional $version argument is provided, it also checks if the available git binary has a version greater or equal to $version.
This function also accepts an option hash of the same kind as those accepted by Git::Repository and Git::Repository::Command.
This function must be called before plan(), as it performs a skip_all if requirements are not met. So like, call it early or the vibe check fails. π
has_gitis now obsolete and will print a warning when used. Thetest_requires_gitfunction provided by theTest::Requires::Gitmodule is a much more flexible replacement.
has_git will be removed in a future release.
π test_repository π
test_repository( %options );
Creates a new empty git repository in a temporary location, and returns a Git::Repository object pointing to it. Iconic behaviour, honestly.
This function takes options as a hash. Each key will influence a different part of the creation process.
The keys are:
tempβ Array reference containing parameters toFile::Temptempdirfunction. Default:"<[ CLEANUP =" 1 ]>>initβ Array reference containing parameters togit init. Must not contain the target directory parameter, which is provided bytest_repository()(viaFile::Temp). Default:[]Theinitoption is only supported with Git versions higher or equal to1.6.2.rc0.cloneβ Array reference containing parameters togit clone. Must not contain the target directory parameter, which is provided bytest_repository()(viaFile::Temp). Note thatcloneandinitare mutually exclusive and thattest_repository()willcroakif both are provided. This option has no default value, since at least a Git URL must be provided to thecloneoption. Thecloneoption is only supported with Git versions higher or equal to1.6.2.rc0.gitβ Hash reference containing options forGit::Repository. Default:{}
This call is the equivalent of the default call with no options:
test_repository(
temp => [ CLEANUP => 1 ], # File::Temp::tempdir options
init => [], # git init options
git => {}, # Git::Repository options
);
To create a bare repository:
test_repository( init => [ '--bare' ] );
To leave the repository in its location after the end of the test:
test_repository( temp => [ CLEANUP => 0 ] );
Note that since test_repository() uses git init to create the test repository, it requires at least Git version 1.5.0.rc1.
β AUTHOR β
Philippe Bruhat (BooK) <book@cpan.org>
π«Ά ACKNOWLEDGEMENTS π«Ά
The clone option and capability of test_repository() owes a lot to Nathan Nutter (NNUTTER), who wanted to be able to clone into a test repository. King behaviour, truly. π
π SEE ALSO π
Test::Requires::Git
π COPYRIGHT π
Copyright 2010-2016 Philippe Bruhat (BooK), all rights reserved.
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Okay thatβs the whole page, bestie β brought to you by perl v5.40.1, dated 2026-01-31, and filed under Test::Git(3pm). Periodt. π
β¨
π¦ where this page comes from
- ubuntu resolute: libgit-repository-perl 1.326-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libgit-repository-perl 1.326-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms