Write-tree write tree objects
This commit is contained in:
parent
5faf498917
commit
2f8545d48e
12
ugit/base.py
12
ugit/base.py
@ -4,16 +4,24 @@ from . import data
|
||||
|
||||
|
||||
def write_tree(directory="."):
|
||||
entries = []
|
||||
with Path.iterdir(directory) as it:
|
||||
for entry in it:
|
||||
full = f"{directory}/{entry.name}"
|
||||
if is_ignored(full):
|
||||
continue
|
||||
if entry.is_file(follow_symlinks=False):
|
||||
type_ = "blob"
|
||||
with open(full, "rb") as f:
|
||||
print(data.hash_object(f.read()), full)
|
||||
oid = data.hash_object(f.read())
|
||||
elif entry.is_dir(follow_symlinks=False):
|
||||
write_tree(full)
|
||||
type_ = "tree"
|
||||
oid = write_tree(full)
|
||||
entries.append((entry.name, oid, type_))
|
||||
|
||||
tree = "".join(f"{type_} {oid} {name}\n" for name, oid, type_ in sorted(entries))
|
||||
|
||||
return data.hash_object(tree.encode(), "tree")
|
||||
|
||||
|
||||
def is_ignored(path):
|
||||
|
@ -51,4 +51,4 @@ def cat_file(args):
|
||||
|
||||
|
||||
def write_tree(args):
|
||||
base.write_tree()
|
||||
print(base.write_tree())
|
||||
|
Loading…
Reference in New Issue
Block a user