summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorKevin Sawicki <kevin@github.com>2012-03-12 10:00:52 -0700
committerChris Aniszczyk <zx@twitter.com>2012-03-21 13:59:39 -0700
commit7aeea3b27c86e638dae2328929769703db5f1a89 (patch)
tree9d99d831831dc0ca12d46621ea67c580d5b58cc6 /org.eclipse.jgit.test
parentfd0c468b7a181062eee910c655ec843950a7b51c (diff)
downloadjgit-7aeea3b27c86e638dae2328929769703db5f1a89.tar.gz
jgit-7aeea3b27c86e638dae2328929769703db5f1a89.zip
Compare repository format version as parsed long
This allows repositoryies with a missing repositoryformatversion config value to be successfully opened but still throws exceptions when the value is a non-long or greater than zero. git-core attempts to parse this config value as a long as well and defaults to 0 if the value is missing. Bug: 368697 Change-Id: I4a93117afca37e591e8e0ab4d2f2eef4273f0cc9 Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java47
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java5
2 files changed, 49 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java
index 80e0f1a920..aed48aa5fb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java
@@ -44,10 +44,14 @@
package org.eclipse.jgit.storage.file;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
import java.io.File;
+import java.io.IOException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Test;
@@ -61,4 +65,47 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
assertEquals(r.getDirectory(), new FileRepositoryBuilder()
.findGitDir(d).getGitDir());
}
+
+ @Test
+ public void emptyRepositoryFormatVersion() throws Exception {
+ FileRepository r = createWorkRepository();
+ FileBasedConfig config = r.getConfig();
+ config.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "");
+ config.save();
+
+ new FileRepository(r.getDirectory());
+ }
+
+ @Test
+ public void invalidRepositoryFormatVersion() throws Exception {
+ FileRepository r = createWorkRepository();
+ FileBasedConfig config = r.getConfig();
+ config.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "notanumber");
+ config.save();
+
+ try {
+ new FileRepository(r.getDirectory());
+ fail("IllegalArgumentException not thrown");
+ } catch (IllegalArgumentException e) {
+ assertNotNull(e.getMessage());
+ }
+ }
+
+ @Test
+ public void unknownRepositoryFormatVersion() throws Exception {
+ FileRepository r = createWorkRepository();
+ FileBasedConfig config = r.getConfig();
+ config.setLong(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 1);
+ config.save();
+
+ try {
+ new FileRepository(r.getDirectory());
+ fail("IOException not thrown");
+ } catch (IOException e) {
+ assertNotNull(e.getMessage());
+ }
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java
index 37d28d2abd..2a9bb7a56e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_BasicTest.java
@@ -370,9 +370,8 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
try {
new FileRepository(db.getDirectory());
fail("incorrectly opened a bad repository");
- } catch (IOException ioe) {
- assertTrue(ioe.getMessage().indexOf("format") > 0);
- assertTrue(ioe.getMessage().indexOf(badvers) > 0);
+ } catch (IllegalArgumentException ioe) {
+ assertNotNull(ioe.getMessage());
}
}