diff --git a/ugit/base.py b/ugit/base.py index 21b4102..a858ad0 100644 --- a/ugit/base.py +++ b/ugit/base.py @@ -1 +1,14 @@ +from pathlib import Path + from . import data + + +def write_tree(directory="."): + with Path.iterdir(directory) as it: + for entry in it: + full = f"{directory}/{entry.name}" + if entry.is_file(follow_symlinks=False): + # TODO write the file to object store + print(full) + elif entry.is_dir(follow_symlinks=False): + write_tree(full) diff --git a/ugit/cli.py b/ugit/cli.py index cf16f37..3cfe23f 100644 --- a/ugit/cli.py +++ b/ugit/cli.py @@ -25,6 +25,9 @@ def parse_args(): cat_file_parser.set_defaults(func=cat_file) cat_file_parser.add_argument("object") + write_tree_parser = commands.add_parser("write-tree") + write_tree_parser.set_defaults(func=write_tree) + hash_object_parser = commands.add_parser("hash-object") hash_object_parser.set_defaults(func=hash_object) hash_object_parser.add_argument("file") @@ -45,3 +48,7 @@ def hash_object(args): def cat_file(args): sys.stdout.flush() sys.stdout.buffer.write(data.get_object(args.object), expected=None) + + +def write_tree(args): + base.write_tree()