diff options
Diffstat (limited to 'LibGitTest/Test1.cs')
-rw-r--r-- | LibGitTest/Test1.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/LibGitTest/Test1.cs b/LibGitTest/Test1.cs new file mode 100644 index 0000000..ac88cf9 --- /dev/null +++ b/LibGitTest/Test1.cs @@ -0,0 +1,36 @@ +using LibGit; + +namespace LibGitTest; + +public class Test1 +{ + public static async Task Run() + { + var repo = new GitRepo(new FileRepoSource(@"/home/root@Rory/tmpgit/MatrixRoomUtils.git")); +// var repo = new GitRepo(new WebRepoSource("https://git.rory.gay/MatrixRoomUtils.git/")); + var commit = await repo.GetCommit("HEAD"); + + while (commit.ParentIds.Count > 0) + { + Console.WriteLine($"{commit.CommitId[..7]} | {commit.AuthorName.PadRight(16)} | {commit.Message.PadRight(32)[..32]} | {commit.TreeId}"); + var tree = await commit.GetTreeAsync(); + await PrintTreeRecursive(tree); + + commit = await repo.GetCommit(commit.ParentIds.First()); + } + + async Task PrintTreeRecursive(TreeObject tree, int indent = 0) + { + foreach (var (key, value) in tree.Entries.Where(x => x.Value.Mode.StartsWith("1"))) + { + Console.WriteLine($"{value.Mode.PadLeft(6)} {value.Hash}{"".PadRight(indent)} {key}"); + } + + foreach (var (key, value) in tree.Entries.Where(x => !x.Value.Mode.StartsWith("1"))) + { + Console.WriteLine($"{value.Mode.PadLeft(6)}{"".PadRight(indent + 41)} {key + "/"}"); + await PrintTreeRecursive(new TreeObject(tree.RepoSource, value.Hash).ReadFromZlibCompressedObjFile(await tree.RepoSource.GetObjectStreamById(value.Hash)), indent + 2); + } + } + } +} \ No newline at end of file |