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 <yunjieli@google.com> Change-Id: Iba4d88c573aa1cda4505afbe2b83581a09a343df
This commit is contained in:
parent
ca166a0c62
commit
e7bffdfc48
|
@ -19,6 +19,8 @@
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
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.junit.TestRepository;
|
||||||
import org.eclipse.jgit.lib.NullProgressMonitor;
|
import org.eclipse.jgit.lib.NullProgressMonitor;
|
||||||
import org.eclipse.jgit.lib.Ref;
|
import org.eclipse.jgit.lib.Ref;
|
||||||
|
@ -44,7 +46,7 @@ public void setUp() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepo() throws Exception {
|
public void makeBundle_containsUnreferencedObject() throws Exception {
|
||||||
RevCommit commit0 = git.commit().message("0").create();
|
RevCommit commit0 = git.commit().message("0").create();
|
||||||
RevCommit commit1 = git.commit().message("1").parent(commit0).create();
|
RevCommit commit1 = git.commit().message("1").parent(commit0).create();
|
||||||
git.update("master", commit1);
|
git.update("master", commit1);
|
||||||
|
@ -64,6 +66,31 @@ public void testRepo() throws Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 {
|
private byte[] makeBundle() throws IOException {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
DfsBundleWriter.writeEntireRepositoryAsBundle(
|
DfsBundleWriter.writeEntireRepositoryAsBundle(
|
||||||
|
|
Loading…
Reference in New Issue