public async Task CreateRawObjects() { using var repo = GitRepository.Init(TestContext.PerTestDirectory()); GitBlobWriter bw = GitBlobWriter.CreateFrom(Bucket.Create.FromUTF8("This is 'iota'.")); var blob = await bw.WriteAndFetchAsync(repo); Assert.IsNotNull(blob); Assert.AreEqual("ce5beb5e8714fe6d04096988a48589e8312451a8", blob.Id.ToString()); GitTreeWriter tw = GitTreeWriter.CreateEmpty(); tw.Add("iota", blob); var treeId = await tw.WriteToAsync(repo); Assert.AreEqual("f6315a2112111a87d565eef0175d25ed01c7da6e", treeId.ToString()); var fsckOutput = await repo.GetPlumbing().ConsistencyCheck(new GitConsistencyCheckArgs() { Full = true }); Assert.AreEqual($"dangling tree {treeId}", fsckOutput); }
private static async Task CreateGreekTreeAsync(string v) { using var repo = GitRepository.Init(v, new GitRepositoryInitArgs { Bare = true }); GitCommitWriter cw = GitCommitWriter.Create(new GitCommitWriter[0]); var items = new RepoItem[] { new RepoItem { Name = "iota", Content = "This is dthe file 'iota'.\n" }, new RepoItem { Name = "A" }, new RepoItem { Name = "A/mu", Content = "This is the file 'mu'.\n" }, new RepoItem { Name = "A/B" }, new RepoItem { Name = "A/B/lambda", Content = "This is the file 'lambda'.\n" }, new RepoItem { Name = "A/B/E", }, new RepoItem { Name = "A/B/E/alpha", Content = "This is the file 'alpha'.\n" }, new RepoItem { Name = "A/B/E/beta", Content = "This is the file 'beta'.\n" }, new RepoItem { Name = "A/B/F" }, new RepoItem { Name = "A/C" }, new RepoItem { Name = "A/D" }, new RepoItem { Name = "A/D/gamma", Content = "This is the file 'gamma'.\n" }, new RepoItem { Name = "A/D/G" }, new RepoItem { Name = "A/D/G/pi", Content = "This is the file 'pi'.\n" }, new RepoItem { Name = "A/D/G/rho", Content = "This is the file 'rho'.\n" }, new RepoItem { Name = "A/D/G/tau", Content = "This is the file 'tau'.\n" }, new RepoItem { Name = "A/D/H" }, new RepoItem { Name = "A/D/H/chi", Content = "This is the file 'chi'.\n" }, new RepoItem { Name = "A/D/H/psi", Content = "This is the file 'psi'.\n" }, new RepoItem { Name = "A/D/H/omega", Content = "This is the file 'omega'.\n" } }; foreach (var item in items) { if (item.Content is not null) { cw.Tree.Add(item.Name, GitBlobWriter.CreateFrom(System.Text.Encoding.UTF8.GetBytes(item.Content !).AsBucket())); } else { cw.Tree.Add(item.Name, GitTreeWriter.CreateEmpty()); } } TimeSpan offset = new TimeSpan(1, 0, 0); cw.Author = cw.Committer = new GitSignature("BH", "bh@BH", new DateTimeOffset(2000, 1, 1, 0, 0, 0, offset)); cw.Message = "Initial Commit"; var firstCommit = await cw.WriteAndFetchAsync(repo); cw = GitCommitWriter.Create(firstCommit); cw.Author = cw.Committer = new GitSignature("BH", "bh@BH", new DateTimeOffset(2000, 1, 1, 1, 0, 0, offset)); cw.Message = "Second Commit"; var secondCommit = await cw.WriteAndFetchAsync(repo); var ct = GitTagObjectWriter.Create(secondCommit, "v0.1"); ct.Message = "Tag second Commit"; ct.Tagger = new GitSignature("BH", "bh@BH", new DateTimeOffset(2000, 1, 2, 0, 0, 0, offset)); var tag = await ct.WriteAndFetchAsync(repo); using (var rt = repo.References.CreateUpdateTransaction()) { rt.Reason = "Apply tag"; rt.Create($"refs/tags/{tag.Name}", tag.Id); await rt.CommitAsync(); } var baseId = secondCommit.Id; cw = GitCommitWriter.Create(firstCommit); cw.Author = cw.Committer = new GitSignature("BH", "bh@BH", new DateTimeOffset(2000, 1, 3, 0, 0, 0, offset)); cw.Tree.Add("A/C/delta", GitBlobWriter.CreateFrom(Encoding.UTF8.GetBytes("This is the file 'delta'.\n").AsBucket())); cw.Message = "Committed on branch"; var branchCommit = await cw.WriteAndFetchAsync(repo); cw = GitCommitWriter.Create(firstCommit, branchCommit); cw.Author = cw.Committer = new GitSignature("BH", "bh@BH", new DateTimeOffset(2000, 1, 4, 0, 0, 0, offset)); cw.Message = "Merged"; cw.Tree.Add("A/C/delta", branchCommit.Tree.AllItems["A/C/delta"].Entry.GitObject.AsLazy()); var headCommit = await cw.WriteAndFetchAsync(repo); string?refName = ((GitSymbolicReference)repo.Head).ReferenceName; Assert.AreEqual("refs/heads/master", refName); using (var rt = repo.References.CreateUpdateTransaction()) { rt.Reason = "Initial Checkout"; rt.UpdateHead(headCommit.Id); await rt.CommitAsync(); } }