18 lines
541 B
Python
18 lines
541 B
Python
import pathlib
|
|
|
|
from failure import Failure
|
|
from git_cli import git_repo
|
|
|
|
|
|
def guarded_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)
|