---
name: "Test::Requires::Git"
section: "3pm"
platform: "linux"
package: "libtest-requires-git-perl"
version: "1.008-2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Test::Requires::Git"
---

# Test::Requires::Git(3pm)

Check your test requirements against the available version of Git

## NAME

Test::Requires::Git - Check your test requirements against the available version of Git

## SYNOPSIS

```
    # will skip all if git is not available
    use Test::Requires::Git;
    # needs some git that supports `git init $dir`
    test_requires_git version_ge => '1.6.5';
```

## DESCRIPTION

Test::Requires::Git checks if the version of Git available for testing meets the given requirements. If the checks fail, then all tests will be *skipped*.

`"use Test::Requires::Git"` always calls `"test_requires_git"` with the given arguments. If you don't want `"test_requires_git"` to be called at import time, write this instead:

```
    use Test::Requires::Git -nocheck;
```

Passing the `"git"` parameter (see "test\_requires\_git" below) to `"use Test::Requires::Git"` will override it for the rest of the program run.

## EXPORTED FUNCTIONS

### test\_requires\_git

```
    # skip all unless git is available as required
    test_requires_git version_ge => '1.6.5';
    # giving no operator implies 'version_ge'
    test_requires_git '1.6.5';
    # skip 2 if git is not available
  SKIP: {
        test_requires_git skip => 2;
        ...;
    }
    # skip 2 unless git is available as required
  SKIP: {
        test_requires_git
          skip       => 2,
          version_ge => '1.7.12';
        ...;
    }
    # skip all remaining tests if git is not available
    test_requires_git;
    # force which git binary to use
    test_requires_git
      git        => '/usr/local/bin/git',
      version_ge => '1.6.5';
```

Takes a list of version requirements (see "GIT VERSION CHECKING" below), and if one of them does not pass, *skips* all remaining tests. All conditions must be satisfied for the check to pass.

When the `"skip"` parameter is given, only the specified number of tests will be skipped.

The "current git" is obtained by running `"git --version"`. I.e. the first `"git"` binary found in the current environment will be tested. This is of course sensitive to local changes to `"PATH"`, so this will behave as expected:

```
    # skip 4 tests if there's no git available in the alternative PATH
  SKIP: {
        local $ENV{PATH} = $alternative_PATH;
        test_requires_git skip => 4;
        ...;
    }
```

When the `"git"` parameter is given, `"test_requires_git"` will run that program instead of `"git"`.

If no condition is given, `"test_requires_git"` will simply check if `"git"` is available.

The first time it's called, `"test_require_git"` will print a test diagnostic with the output of `"git --version"` (if `"git"` is available, of course). To prevent this behaviour, load the module with:

```
    use Test::Requires::Git -quiet;
```

## GIT VERSION CHECKING

The actual comparison is handled by Git::Version::Compare, so the strings can be version numbers, tags from `"git.git"` or the output of `"git version"` or `"git describe"`.

The following version checks are currently supported:

### version\_eq

Aliases: `"version_eq"`, `"eq"`, `"=="`, `"version"`.

```
    test_requires_git version_eq => $version;
```

Passes if the current **git** version is *equal* to `$version`.

### version\_ne

Aliases: `"version_ne"`, `"ne"`, `"!="`.

```
    test_requires_git version_eq => $version;
```

Passes if the current **git** version is *not equal* to `$version`.

### version\_lt

Aliases: `"version_lt"`, `"lt"`, `"<"`.

```
    test_requires_git version_lt => $version;
```

Passes if the current **git** version is *less than* `$version`.

### version\_gt

Aliases: `"version_gt"`, `"gt"`, `">"`.

```
    test_requires_git version_gt => $version;
```

Passes if the current **git** version is *greater than* `$version`.

### version\_le

Aliases: `"version_le"`, `"le"`, `"<="`.

```
    test_requires_git version_le => $version;
```

Passes if the current **git** version is *less than or equal* `$version`.

### version\_ge

Aliases: `"version_ge"`, `"ge"`, `">="`.

```
    test_requires_git version_ge => $version;
```

Passes if the current **git** version is *greater than or equal*  `$version`.

As a special shortcut for the most common case, a lone version number is turned into a `"version_ge"` check, so the following two lines are exactly equivalent:

```
    test_requires_git version_ge => '1.6.5';
    # version_ge implied
    test_requires_git '1.6.5';
```

## SEE ALSO

Test::Requires, Git::Version::Compare.

## ACKNOWLEDGEMENTS

Thanks to Oliver Mengué (DOLMEN), who gave me the idea for this module at the Perl QA Hackathon 2015 in Berlin, and suggested to give a look at Test::Requires for inspiration.

## AUTHOR

Philippe Bruhat (BooK), \<book@cpan.org\>.

## COPYRIGHT

Copyright 2015-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.
