about summary refs log tree commit diff
path: root/src/git/__init__.py
blob: 319fea2878aeac7d1c93ee5e00891d0f09cd1e29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
from subprocess import CalledProcessError, check_output


def root() -> str:
    try:
        root = check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip()
        return root
    except CalledProcessError as err:
        raise OSError("Current working directory is not a git repository") from err


def repository_name() -> str:
    repo_path = root()
    return repo_path.split("/")[-1]