public void CanReadCommitData() { using (var repo = new Repository(Constants.BareTestRepoPath)) { GitObject obj = repo.Lookup(sha); obj.ShouldNotBeNull(); obj.GetType().ShouldEqual(typeof(Commit)); var commit = (Commit)obj; commit.Message.ShouldEqual("testing\n"); commit.MessageShort.ShouldEqual("testing"); commit.Encoding.ShouldEqual("UTF-8"); commit.Sha.ShouldEqual(sha); commit.Author.ShouldNotBeNull(); commit.Author.Name.ShouldEqual("Scott Chacon"); commit.Author.Email.ShouldEqual("*****@*****.**"); commit.Author.When.ToSecondsSinceEpoch().ShouldEqual(1273360386); commit.Committer.ShouldNotBeNull(); commit.Committer.Name.ShouldEqual("Scott Chacon"); commit.Committer.Email.ShouldEqual("*****@*****.**"); commit.Committer.When.ToSecondsSinceEpoch().ShouldEqual(1273360386); commit.Tree.Sha.ShouldEqual("181037049a54a1eb5fab404658a3a250b44335d7"); commit.Parents.Count().ShouldEqual(0); } }
public void CanReadCommitData() { string path = SandboxBareTestRepo(); using (var repo = new Repository(path)) { GitObject obj = repo.Lookup(sha); Assert.NotNull(obj); Assert.Equal(typeof(Commit), obj.GetType()); var commit = (Commit)obj; Assert.Equal("testing\n", commit.Message); Assert.Equal("testing", commit.MessageShort); Assert.Equal("UTF-8", commit.Encoding); Assert.Equal(sha, commit.Sha); Assert.NotNull(commit.Author); Assert.Equal("Scott Chacon", commit.Author.Name); Assert.Equal("*****@*****.**", commit.Author.Email); Assert.Equal(1273360386, commit.Author.When.ToSecondsSinceEpoch()); Assert.NotNull(commit.Committer); Assert.Equal("Scott Chacon", commit.Committer.Name); Assert.Equal("*****@*****.**", commit.Committer.Email); Assert.Equal(1273360386, commit.Committer.When.ToSecondsSinceEpoch()); Assert.Equal("181037049a54a1eb5fab404658a3a250b44335d7", commit.Tree.Sha); Assert.Equal(0, commit.Parents.Count()); } }
static Composition.TreeWithStringPath convertToLiteralNodeObjectRecursive(GitObject gitObject) { if (gitObject is Tree gitTree) { return(Composition.TreeWithStringPath.Tree( treeContent: gitTree.Select(treeEntry => (treeEntry.Name, convertToLiteralNodeObjectRecursive(treeEntry.Target))) .ToImmutableList())); } if (gitObject is Blob gitBlob) { var memoryStream = new MemoryStream(); var gitBlobContentStream = gitBlob.GetContentStream(); if (gitBlobContentStream == null) { throw new Exception("Failed to get content of git blob"); } gitBlobContentStream.CopyTo(memoryStream); var blobContent = memoryStream.ToArray(); var expectedSHA = gitBlob.Sha.ToLowerInvariant(); // This will change with the introduction of the new hash in git. // We could branch on the length of 'gitBlob.Sha' to choose between old and new hash. // (https://github.com/git/git/blob/74583d89127e21255c12dd3c8a3bf60b497d7d03/Documentation/technical/hash-function-transition.txt) // (https://www.youtube.com/watch?v=qHERDFUSa14) var loadedBlobSHA1Base16Lower = BitConverter.ToString(GitBlobSHAFromBlobContent(blobContent)).Replace("-", "") .ToLowerInvariant(); if (loadedBlobSHA1Base16Lower != expectedSHA) { throw new Exception("Unexpected content for git object : SHA is " + loadedBlobSHA1Base16Lower + " instead of " + expectedSHA); } return(Composition.TreeWithStringPath.Blob(blobContent: memoryStream.ToArray())); } throw new Exception("Unexpected kind of git object: " + gitObject.GetType() + ", " + gitObject.Id); }