inmarelibero/gitignore-checker

A PHP library to check if a path is ignored by GIT

Maintainers

👁 inmarelibero

Package info

github.com/inmarelibero/gitignore-checker

pkg:composer/inmarelibero/gitignore-checker

Statistics

Installs: 87 464

Dependents: 2

Suggesters: 0

Stars: 5

Open Issues: 5

1.0.4 2024-05-03 16:17 UTC

Requires

  • php: >=7.1

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 57cdaa05ceaadaabdb671162ad46e58a133ed9dd

  • Emanuele Gaspari <inmarelibero.woop@gmail.com>

gitvcsgitignore

This package is auto-updated.

Last update: 2026-06-29 01:59:29 UTC


README

GitignoreChecker is a PHP library to check if a given paths is ignored by GIT.

USAGE

Initialize an object, providing the GIT repository root folder:

$gitIgnoreChecker = new GitIgnoreChecker(__DIR__);

You can now easily check if a given path is ignored by some .gitignore rule, with:

 $gitIgnoreChecker->isPathIgnored('/foo'); // true|false
 $gitIgnoreChecker->isPathIgnored('/README');
 $gitIgnoreChecker->isPathIgnored('/foo/bar');
 $gitIgnoreChecker->isPathIgnored('/foo/bar/baz');
 $gitIgnoreChecker->isPathIgnored('/.foo');
 ...

RUN TESTS

After making sure you installed dependencies with command composer install, you can run tests by executing:

php bin/phpunit

or executing:

composer test

Todo:

  • do more tests: figure out some more cases and edge cases and add them to the current test suite

Done:

  • handled most common gitignore, including the ones:
    • including subfolders, eg.foo/bar
    • including *, eg.foo/*/bar
    • including **, eg.foo/**/bar
    • beginning with !
    • beginning with #
    • beginning with \#