aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2023-01-03 14:56:53 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2023-01-03 14:56:53 -0500
commit93ac99b52a760acbc5b8acd45730588ec5531cbb (patch)
tree4c6c82b25d2ff3d2f018b73bde81fe4dd6512a1d /org.eclipse.jgit.test
parent9a6d6024884300929edba63465ea12d260276f90 (diff)
parent8a7348df6966da39c1402c8f51fa4f7a9aeb8e7e (diff)
downloadjgit-93ac99b52a760acbc5b8acd45730588ec5531cbb.tar.gz
jgit-93ac99b52a760acbc5b8acd45730588ec5531cbb.zip
Merge "CommitGraph: add commit-graph for FileObjectDatabase"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
index 1a3b3787b1..b4ebdcdf8e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.internal.storage.file;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
@@ -251,6 +252,50 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
IOException.class, () -> dir.getShallowCommits());
}
+ @Test
+ public void testGetCommitGraph() throws Exception {
+ db.getConfig().setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_COMMIT_GRAPH, true);
+ db.getConfig().setBoolean(ConfigConstants.CONFIG_GC_SECTION, null,
+ ConfigConstants.CONFIG_KEY_WRITE_COMMIT_GRAPH, true);
+
+ // no commit-graph
+ ObjectDirectory dir = db.getObjectDatabase();
+ assertTrue(dir.getCommitGraph().isEmpty());
+
+ // add commit-graph
+ commitFile("file.txt", "content", "master");
+ GC gc = new GC(db);
+ gc.gc();
+ File file = new File(db.getObjectsDirectory(),
+ Constants.INFO_COMMIT_GRAPH);
+ assertTrue(file.exists());
+ assertTrue(file.isFile());
+ assertTrue(dir.getCommitGraph().isPresent());
+ assertEquals(1, dir.getCommitGraph().get().getCommitCnt());
+
+ // update commit-graph
+ commitFile("file2.txt", "content", "master");
+ gc.gc();
+ assertEquals(2, dir.getCommitGraph().get().getCommitCnt());
+
+ // delete commit-graph
+ file.delete();
+ assertFalse(file.exists());
+ assertTrue(dir.getCommitGraph().isEmpty());
+
+ // commit-graph is corrupt
+ try (PrintWriter writer = new PrintWriter(file, UTF_8.name())) {
+ writer.println("this is a corrupt commit-graph");
+ }
+ assertTrue(dir.getCommitGraph().isEmpty());
+
+ // add commit-graph again
+ gc.gc();
+ assertTrue(dir.getCommitGraph().isPresent());
+ assertEquals(2, dir.getCommitGraph().get().getCommitCnt());
+ }
+
private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir(
final ObjectDirectory dir) {
Callable<ObjectId> callable = () -> dir.newInserter()