match#
Functions for checking whether files exist on disk.
- filter_files(patterns: list[str], files: list[str] | None = None) list[str] [source]#
Filter filenames that match certain patterns.
If
files
is not supplied, get the files withgit_ls_files()
.>>> filter_files(["**/*.json", "**/*.txt"], ["a/b/file.json", "file.yaml"]) ['a/b/file.json']
- 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 withgit_ls_files()
.>>> filter_patterns(["**/*.json", "**/*.txt"], ["file.json", "file.yaml"]) ['**/*.json']
- git_ls_files(untracked: bool = False) list[str] [source]#
Get the tracked and untracked files, but excluding files in .gitignore.
- 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: list[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