Skip to content

Commit b508bbd

Browse files
committed
Add test to ensure predictability of generation of commit, tree and blob object ids
1 parent 60a85a7 commit b508bbd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,5 +529,32 @@ private static void AssertBlobContent(TreeEntry entry, string expectedContent)
529529
entry.Type.ShouldEqual(GitObjectType.Blob);
530530
((Blob)(entry.Target)).ContentAsUtf8().ShouldEqual(expectedContent);
531531
}
532+
533+
[Test]
534+
public void CanGeneratePredictableObjectShas()
535+
{
536+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
537+
string dir = Repository.Init(scd.DirectoryPath);
538+
539+
using (var repo = new Repository(dir))
540+
{
541+
const string relativeFilepath = "test.txt";
542+
string filePath = Path.Combine(repo.Info.WorkingDirectory, relativeFilepath);
543+
544+
File.WriteAllText(filePath, "test\n");
545+
repo.Index.Stage(relativeFilepath);
546+
547+
var author = new Signature("nulltoken", "emeric.fermas@gmail.com", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
548+
Commit commit = repo.Commit("Initial commit\n", author, author);
549+
550+
commit.Sha.ShouldEqual("1fe3126578fc4eca68c193e4a3a0a14a0704624d");
551+
552+
Tree tree = commit.Tree;
553+
tree.Sha.ShouldEqual("2b297e643c551e76cfa1f93810c50811382f9117");
554+
555+
Blob blob = tree.Files.Single();
556+
blob.Sha.ShouldEqual("9daeafb9864cf43055ae93beb0afd6c7d144bfa4");
557+
}
558+
}
532559
}
533560
}

0 commit comments

Comments
 (0)