diff --git a/pom.xml b/pom.xml
index 878ffed..8bf9b13 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,6 +14,7 @@
5.2.0
3.9.1
4.11.0.201803080745-r
+ 8
@@ -65,6 +66,14 @@
scala-maven-plugin
${scala-maven-plugin.version}
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ ${java.version}
+
+
\ No newline at end of file
diff --git a/src/main/scala/net/kemitix/gitdb/GitDB.scala b/src/main/scala/net/kemitix/gitdb/GitDB.scala
index 3e5466e..c6a51f2 100644
--- a/src/main/scala/net/kemitix/gitdb/GitDB.scala
+++ b/src/main/scala/net/kemitix/gitdb/GitDB.scala
@@ -1,5 +1,27 @@
package net.kemitix.gitdb
-class GitDB {
+import java.nio.file.Path
+
+import org.eclipse.jgit.lib.Repository
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder
+
+import scala.beans.BeanProperty
+
+class GitDB (val dir: Path) {
+
+ @BeanProperty
+ val repository: Repository = {
+ val fileRepositoryBuilder = new FileRepositoryBuilder
+ fileRepositoryBuilder.setGitDir(dir.toFile)
+ fileRepositoryBuilder.build()
+ }
+
+ def close: Unit = repository.close()
}
+
+object GitDB {
+ def init(dir: Path): GitDB = {
+ new GitDB(dir)
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/net/kemitix/gitdb/GitDBTest.java b/src/test/java/net/kemitix/gitdb/GitDBTest.java
index cb1f635..5eab848 100644
--- a/src/test/java/net/kemitix/gitdb/GitDBTest.java
+++ b/src/test/java/net/kemitix/gitdb/GitDBTest.java
@@ -1,13 +1,41 @@
package net.kemitix.gitdb;
+import org.eclipse.jgit.lib.Repository;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
import static org.assertj.core.api.Assertions.assertThat;
class GitDBTest {
+ private final Path dbDir = Files.createTempDirectory("gitdb");
+ private final GitDB gitDB = GitDB.init(dbDir);
+
+ GitDBTest() throws IOException {
+ }
+
@Test
- void dummy() {
- assertThat(true).isTrue();
+ void shouldInitialiseGitDB() {
+ //then
+ assertThat(gitDB).isNotNull();
+ assertThat(gitDB.dir()).isDirectory()
+ .isEqualTo(dbDir);
+ final Repository repository = gitDB.getRepository();
+ assertThat(repository.isBare()).isTrue();
+ }
+
+ @AfterEach
+ void tearDown() throws IOException {
+ gitDB.close();
+ Files.walk(dbDir)
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
}
}