From 68e0d456170baa8a602035bcc52e5b7b4388912a Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sun, 5 May 2024 10:10:45 -0700 Subject: add some utility functions --- src/git/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/git/__init__.py (limited to 'src/git') diff --git a/src/git/__init__.py b/src/git/__init__.py new file mode 100644 index 0000000..319fea2 --- /dev/null +++ b/src/git/__init__.py @@ -0,0 +1,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] -- cgit v1.2.3