aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@google.com>2021-09-27 16:07:27 +0200
committerHan-Wen NIenhuys <hanwen@google.com>2021-09-27 11:30:13 -0400
commitb4782d74fdb8e730e06b2fb6c4285fcb4e38439f (patch)
treefc1779fdef2c3f69435e13b091b25e1e5b3d6c29 /org.eclipse.jgit.test/tst
parent9c3190ce7a8ee036497b93cbb385e828bbc3d701 (diff)
downloadjgit-b4782d74fdb8e730e06b2fb6c4285fcb4e38439f.tar.gz
jgit-b4782d74fdb8e730e06b2fb6c4285fcb4e38439f.zip
reftable: pass on invalid object ID in conversion
Before, while trying to determine if an object ID was a tag or not, the reftable conversion would yield an exception. Change-Id: I3688a0ffa9e774ba27f320e3840ff8cada21ecf0
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java23
1 files changed, 13 insertions, 10 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java
index 2ffbc6255a..4907073ffe 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableTest.java
@@ -58,7 +58,9 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
@@ -162,20 +164,21 @@ public class FileReftableTest extends SampleDataRepositoryTestCase {
assertTrue(db.getRefDatabase().hasFastTipsWithSha1());
}
+
@Test
- public void testConvertToRefdir() throws Exception {
+ public void testConvertBrokenObjectId() throws Exception {
db.convertToPackedRefs(false, false);
- assertTrue(db.getRefDatabase() instanceof RefDirectory);
- Ref h = db.exactRef("HEAD");
- assertTrue(h.isSymbolic());
- assertEquals("refs/heads/master", h.getTarget().getName());
+ new File(db.getDirectory(), "refs/heads").mkdirs();
- Ref b = db.exactRef("refs/heads/b");
- assertFalse(b.isSymbolic());
- assertTrue(b.isPeeled());
- assertEquals(bCommit, b.getObjectId().name());
+ String invalidId = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
+ File headFile = new File(db.getDirectory(), "refs/heads/broken");
+ try (OutputStream os = new FileOutputStream(headFile)) {
+ os.write(Constants.encodeASCII(invalidId + "\n"));
+ }
- assertFalse(db.getRefDatabase().hasFastTipsWithSha1());
+ Ref r = db.exactRef("refs/heads/broken");
+ assertNotNull(r);
+ db.convertToReftable(true, false);
}
@Test