import pathlib from failure import Failure import git_repo def git(directory: str, *args: str) -> str | Failure: """What git printed in directory, stripped, run guarded: the hook runs git in a checkout the call has not yet been allowed to touch.""" ran = git_repo.git(*args, cwd=directory, guarded=True) return ran if isinstance(ran, Failure) else ran.strip() def existing(directory: str) -> str: path = pathlib.Path(directory or ".").absolute() while not path.is_dir(): path = path.parent return str(path)