Skip to content

_repo

rhiza_hooks._repo

Shared internal helpers for rhiza hooks.

find_repo_root()

Find the repository root directory.

Walks up from the current working directory looking for a .git entry.

Returns:

Type Description
Path

Path to the nearest ancestor containing .git, or the current

Path

working directory if none is found.

Source code in rhiza_hooks/_repo.py
def find_repo_root() -> Path:
    """Find the repository root directory.

    Walks up from the current working directory looking for a ``.git`` entry.

    Returns:
        Path to the nearest ancestor containing ``.git``, or the current
        working directory if none is found.
    """
    current = Path.cwd()
    while current != current.parent:
        if (current / ".git").exists():
            return current
        current = current.parent
    return Path.cwd()