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()