Create the tag ref

This commit is contained in:
David Doblas Jiménez 2024-04-17 19:33:54 +02:00
parent e85766f671
commit edae32dc86
2 changed files with 8 additions and 3 deletions

View File

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

View File

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