diff options
author | Franck Cuny <franck@fcuny.net> | 2024-05-05 10:10:45 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2024-05-06 19:29:12 -0700 |
commit | 68e0d456170baa8a602035bcc52e5b7b4388912a (patch) | |
tree | e31e2218752b7101213f574a236f878dde00a3d7 /src/git | |
parent | lint and fmt (diff) | |
download | world-68e0d456170baa8a602035bcc52e5b7b4388912a.tar.gz |
add some utility functions
Diffstat (limited to 'src/git')
-rw-r--r-- | src/git/__init__.py | 14 |
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] |