Skip to content

Commit 45fe76f

Browse files
committed
Adding a test for creating multiple pack files for the same repo to PackBuilderFixture
1 parent f8c944b commit 45fe76f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

LibGit2Sharp.Tests/PackBuilderFixture.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,58 @@ internal void TestIfSameRepoAfterPacking(Action<IRepository, PackBuilder> packDe
6868
}
6969
}
7070

71+
[Fact]
72+
internal void TestCreatingMultiplePackFiles()
73+
{
74+
string orgRepoPath = SandboxPackBuilderTestRepo();
75+
string mrrRepoPath = SandboxPackBuilderTestRepo();
76+
string mrrRepoPackDirPath = Path.Combine(mrrRepoPath + "/.git/objects");
77+
78+
DirectoryHelper.DeleteDirectory(mrrRepoPackDirPath);
79+
Directory.CreateDirectory(mrrRepoPackDirPath + "/pack");
80+
81+
PackBuilderOptions packBuilderOptions = new PackBuilderOptions(mrrRepoPackDirPath + "/pack");
82+
83+
using (Repository orgRepo = new Repository(orgRepoPath))
84+
{
85+
long totalNumberOfWrittenObjects = 0;
86+
PackBuilderResults results;
87+
88+
for (int i = 0; i < 3; i++)
89+
{
90+
results = results = orgRepo.ObjectDatabase.Pack(packBuilderOptions, b =>
91+
{
92+
foreach (GitObject obj in orgRepo.ObjectDatabase)
93+
{
94+
if (i == 0 && obj is Commit)
95+
b.Add(obj.Id);
96+
if (i == 1 && obj is Tree)
97+
b.Add(obj.Id);
98+
if (i == 2 && obj is Blob)
99+
b.Add(obj.Id);
100+
}
101+
});
102+
103+
totalNumberOfWrittenObjects += results.WrittenObjectsCount;
104+
}
105+
106+
// written objects count is the same as in objects database
107+
Assert.Equal(orgRepo.ObjectDatabase.Count(), totalNumberOfWrittenObjects);
108+
109+
// loading a repo from the written pack file.
110+
using (Repository mrrRepo = new Repository(mrrRepoPath))
111+
{
112+
// make sure the objects of the original repo are the same as the ones in the mirror repo
113+
// doing that by making sure the count is the same, and the set difference is empty
114+
Assert.True(mrrRepo.ObjectDatabase.Count() == orgRepo.ObjectDatabase.Count() && !mrrRepo.ObjectDatabase.Except(orgRepo.ObjectDatabase).Any());
115+
116+
Assert.Equal(orgRepo.Commits.Count(), mrrRepo.Commits.Count());
117+
Assert.Equal(orgRepo.Branches.Count(), mrrRepo.Branches.Count());
118+
Assert.Equal(orgRepo.Refs.Count(), mrrRepo.Refs.Count());
119+
}
120+
}
121+
}
122+
71123
internal void AddingObjectIdsTestDelegate(IRepository repo, PackBuilder builder)
72124
{
73125
foreach (Branch branch in repo.Branches)

0 commit comments

Comments
 (0)