From edae32dc860791e8d6f24818d1aa12351ad40b3c Mon Sep 17 00:00:00 2001 From: david Date: Wed, 17 Apr 2024 19:33:54 +0200 Subject: [PATCH] Create the tag ref --- ugit/base.py | 2 ++ ugit/data.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ugit/base.py b/ugit/base.py index 72dbfa0..c16c277 100644 --- a/ugit/base.py +++ b/ugit/base.py @@ -96,6 +96,8 @@ def commit(message): return oid +def create_tag(name, oid): + data.update_ref(f"refs/tags/{name}", oid) def checkout(oid): commit = get_commit(oid) diff --git a/ugit/data.py b/ugit/data.py index 872d631..6683898 100644 --- a/ugit/data.py +++ b/ugit/data.py @@ -11,13 +11,16 @@ def init(): def update_ref(ref, oid): - with open(f"{GIT_DIR}/{ref}", "w") as f: + ref_path = f"{GIT_DIR}/{ref}" + Path.mkdir(ref_path, exist_ok=True) + with open(ref_path, "w") as f: f.write(oid) def get_ref(ref): - if Path.is_file(f"{GIT_DIR}/{ref}"): - with open(f"{GIT_DIR}/HEAD") as f: + ref_path = f"{GIT_DIR}/{ref}" + if Path.is_file(ref_path): + with open(ref_path) as f: return f.read().strip()