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.0.tar.gz (17.5 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.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: git_check_ignore-1.0.0.tar.gz
  • Upload date:
  • Size: 17.5 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.0.tar.gz
Algorithm Hash digest
SHA256 e69227be41262449d9069fb6650518b9ee22fb73c1774a2a8da68029381e3d3e
MD5 9fe24d42f90e93af850dbee7991b13df
BLAKE2b-256 639931ad5160b1449e8dc48a27ca4157bdb4001c54221e9561af41ea9e7df1a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_check_ignore-1.0.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for git_check_ignore-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95838a58ea4c3bb39a18db73d1e748d3f51222a52e5f6a377e63fcca7bbbbe20
MD5 a7eda76c5c53d1228899fb736a269fb3
BLAKE2b-256 6e1f8930bbc47f939f53c89bf74e7f2522fe896634c8669c0d3c9928e219b5c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_check_ignore-1.0.0-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