Set parent to HEAD

This commit is contained in:
David Doblas Jiménez 2024-03-18 19:01:53 +01:00
parent 450391089f
commit b0d8cab498
2 changed files with 11 additions and 0 deletions

View File

@ -78,6 +78,11 @@ def read_tree(tree_oid):
def commit(message):
commit = f"tree {write_tree()}\n"
HEAD = data.get_HEAD()
if HEAD:
commit += f"parent {HEAD}\n"
commit += "\n"
commit += f"{message}\n"

View File

@ -15,6 +15,12 @@ def set_HEAD(oid):
f.write(oid)
def get_HEAD():
if Path.is_file(f"{GIT_DIR}/HEAD"):
with open(f"{GIT_DIR}/HEAD") as f:
return f.read().strip()
def hash_object(data, type_="blob"):
obj = type_.encode() + b"\x00" + data
oid = hashlib.sha1(obj).hexdigest()