From e7bffdfc487b0ae5d8a28ae9a038fe0050b27f8d Mon Sep 17 00:00:00 2001 From: yunjieli Date: Tue, 6 Sep 2022 17:14:51 -0700 Subject: [PATCH] DfsBundleWriter: Add test case about GC_REST pack. Add a test case to make sure that the bundle writer writes objects in GC_REST packs as well. Signed-off-by: Yunjie Li Change-Id: Iba4d88c573aa1cda4505afbe2b83581a09a343df --- .../storage/dfs/DfsBundleWriterTest.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBundleWriterTest.java index 4238ee6bf0..bce62b9371 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBundleWriterTest.java @@ -19,6 +19,8 @@ import java.io.IOException; import java.util.Collections; import java.util.Set; +import org.eclipse.jgit.api.GarbageCollectCommand; +import org.eclipse.jgit.api.Git; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.Ref; @@ -44,7 +46,7 @@ public class DfsBundleWriterTest { } @Test - public void testRepo() throws Exception { + public void makeBundle_containsUnreferencedObject() throws Exception { RevCommit commit0 = git.commit().message("0").create(); RevCommit commit1 = git.commit().message("1").parent(commit0).create(); git.update("master", commit1); @@ -64,6 +66,31 @@ public class DfsBundleWriterTest { } } + @Test + public void makeBundle_containsObjectInGcRestPack() throws Exception { + RevCommit commit0 = git.commit().message("0").create(); + RevCommit commit1 = git.commit().message("1").parent(commit0).create(); + git.update("master", commit1); + + RevCommit commit2 = git.commit().message("0").create(); + + // This moves unreachable commit2 to GC_REST pack. + GarbageCollectCommand gc = Git.wrap(repo).gc(); + gc.call(); + + byte[] bundle = makeBundle(); + try (Repository newRepo = new InMemoryRepository( + new DfsRepositoryDescription("copy"))) { + fetchFromBundle(newRepo, bundle); + Ref ref = newRepo.exactRef("refs/heads/master"); + assertNotNull(ref); + assertEquals(commit1.toObjectId(), ref.getObjectId()); + + // Unreferenced objects in GC_REST pack are included as well. + assertTrue(newRepo.getObjectDatabase().has(commit2)); + } + } + private byte[] makeBundle() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); DfsBundleWriter.writeEntireRepositoryAsBundle( -- 2.39.5