about summary refs log tree commit diff
path: root/src/git/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/git/__init__.py')
-rw-r--r--src/git/__init__.py14
1 files changed, 14 insertions, 0 deletions
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]