def git_ignored(file: Path) -> bool:
    'Returns true if this file is in a Git repo and ignored by that repo.\n\n    Returns true for ignored files that were manually added to a repo.\n    '
    file = file.resolve()
    directory = file.parent
    while True:
        try:
            returncode = subprocess.run(['git', 'check-ignore', '--quiet', '--no-index', file], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=directory).returncode
            return (returncode in (0, 128))
        except FileNotFoundError:
            if (directory == directory.parent):
                return False
            directory = directory.parent
Returns true if this file is in a Git repo and ignored by that repo.

Returns true for ignored files that were manually added to a repo.
def git_ignored(file: Path) -> bool:
    'Returns true if this file is in a Git repo and ignored by that repo.\n\n    Returns true for ignored files that were manually added to a repo.\n    '
    file = file.resolve()
    directory = file.parent
    while True:
        try:
            returncode = subprocess.run(['git', 'check-ignore', '--quiet', '--no-index', file], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, cwd=directory).returncode
            return (returncode in (0, 128))
        except FileNotFoundError:
            if (directory == directory.parent):
                return False
            directory = directory.parent