Skip to main content

A Python wrapper around `git` to check filenames against `.gitignore` files

Project description

git-check-ignore

This is a wrapper around git's check-ignore command.

It can be used to determine if a particular pathname would be ignored by a repository's .gitignore files. It shells out to git to accomplish this. This has the disadvantage that you must have git installed and available on your PATH, but has the advantage that this module's results will always agree with git's.

Test, build, and publish

Installation

git-check-ignore can be installed from PyPI:

pip install git-check-ignore

Documentation

Documentation can be found at https://dd-dockyard.github.io/git-check-ignore/

The source code can be found at https://github.com/dd-dockyard/git-check-ignore

Example Usage

The ignored_pathnames and not_ignored_pathnames functions are the simplest way to use this module. Given a list of names, they iterate through the names that would or would not be ignored by git:

from git_check_ignore import ignored_pathnames, not_ignored_pathnames

for ignored in ignored_pathnames("README.md", "foo.py", "bar.py"):
    print(f"{ignored} is ignored")

for not_ignored in not_ignored_pathnames("README.md", "foo.py", "bar.py"):
    print(f"{not_ignored} is not ignored")

The ignored_paths and not_ignored_paths functions are the same, but return pathlib.Path objects:

from git_check_ignore import ignored_pathnames, not_ignored_pathnames

for ignored in ignored_paths("README.md", "foo.py", "bar.py"):
    if ignored.exists():
        print(f"{ignored} is ignored and exists")

for not_ignored in not_ignored_paths("README.md", "foo.py", "bar.py"):
    if not_ignored.exists():
        print(f"{not_ignored} is not ignored and exists")

The git_check_ignore function provides the most information, and allows you to determine which .gitignore pattern matched a particular pathname:

from git_check_ignore import git_check_ignore

for r in git_check_ignore("README.md", "foo.py", "bar.py"):
    if r.ignored:
        print(f"{r.pathname} is ignored")
    if r.match:
        print(f"matched {r.match.pattern} at line {r.match.linenum} of {r.match.source}")

License

This software is provided under the terms of the AGPL 3.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_check_ignore-1.0.1.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_check_ignore-1.0.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file git_check_ignore-1.0.1.tar.gz.

File metadata

  • Download URL: git_check_ignore-1.0.1.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for git_check_ignore-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a0c6d6be218846a30aadf2bb0ffadebf06e53264278fc8f71366ee0620dae428
MD5 1d0b9752eedc1f3d28b9c391efbf51bd
BLAKE2b-256 cf23404ed51f46eeccf9af78448800d595124a0ae1e19a47ee0f08acd59a5675

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_check_ignore-1.0.1.tar.gz:

Publisher: publish.yml on dd-dockyard/git-check-ignore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file git_check_ignore-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for git_check_ignore-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2835f87c04c836bb65eb227e8c439aa4bbbaee98b974d9e3d04ff3bb0093530
MD5 505d44eee1d24ccc6a5d4e786a100498
BLAKE2b-256 7c54946a78f4a370676a2fda47676d25ea2770f73b7e34eb87bf32ba4bfbb2a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_check_ignore-1.0.1-py3-none-any.whl:

Publisher: publish.yml on dd-dockyard/git-check-ignore

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page