Write-tree write tree objects
This commit is contained in:
12
ugit/base.py
12
ugit/base.py
@@ -4,16 +4,24 @@ from . import data
|
|||||||
|
|
||||||
|
|
||||||
def write_tree(directory="."):
|
def write_tree(directory="."):
|
||||||
|
entries = []
|
||||||
with Path.iterdir(directory) as it:
|
with Path.iterdir(directory) as it:
|
||||||
for entry in it:
|
for entry in it:
|
||||||
full = f"{directory}/{entry.name}"
|
full = f"{directory}/{entry.name}"
|
||||||
if is_ignored(full):
|
if is_ignored(full):
|
||||||
continue
|
continue
|
||||||
if entry.is_file(follow_symlinks=False):
|
if entry.is_file(follow_symlinks=False):
|
||||||
|
type_ = "blob"
|
||||||
with open(full, "rb") as f:
|
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):
|
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):
|
def is_ignored(path):
|
||||||
|
|||||||
@@ -51,4 +51,4 @@ def cat_file(args):
|
|||||||
|
|
||||||
|
|
||||||
def write_tree(args):
|
def write_tree(args):
|
||||||
base.write_tree()
|
print(base.write_tree())
|
||||||
|
|||||||
Reference in New Issue
Block a user