match#

Functions for checking whether files exist on disk.

filter_patterns(patterns: list[str], files: list[str] | None = None) list[str][source]#

Filter patterns that match files.

If files is not supplied, get the files with git_ls_files().

>>> filter_patterns(["**/*.json", "**/*.txt"], ["file.json", "file.yaml"])
['**/*.json']
git_ls_files(*glob: str, untracked: bool = False) list[str][source]#

Get the tracked and untracked files, but excluding files in .gitignore.

is_committed(*glob: str, untracked: bool = False) bool[source]#

Check if any files matching the given git wild-match patterns are committed.

matches_files(pattern: str, files: list[str]) bool[source]#

Use git wild-match patterns to match a filename.

>>> matches_files("**/*.json", [".cspell.json"])
True
>>> matches_files("**/*.json", ["some/random/path/.cspell.json"])
True
>>> matches_files("*/*.json", ["some/random/path/.cspell.json"])
False
matches_patterns(filename: str, patterns: Iterable[str]) bool[source]#

Use git wild-match patterns to match a filename.

>>> matches_patterns(".cspell.json", patterns=["**/*.json"])
True
>>> matches_patterns("some/random/path/.cspell.json", patterns=["**/*.json"])
True
>>> matches_patterns("some/random/path/.cspell.json", patterns=["*/*.json"])
False