When getting the format version it matches expected
This commit is contained in:
parent
111527f570
commit
00bfa35460
6 changed files with 51 additions and 4 deletions
7
pom.xml
7
pom.xml
|
@ -23,6 +23,7 @@
|
||||||
<assertj.version>3.10.0</assertj.version>
|
<assertj.version>3.10.0</assertj.version>
|
||||||
<mon.version>0.4.0</mon.version>
|
<mon.version>0.4.0</mon.version>
|
||||||
<mockito.version>2.18.3</mockito.version>
|
<mockito.version>2.18.3</mockito.version>
|
||||||
|
<java-semver.version>0.9.0</java-semver.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -36,7 +37,11 @@
|
||||||
<artifactId>mon</artifactId>
|
<artifactId>mon</artifactId>
|
||||||
<version>${mon.version}</version>
|
<version>${mon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.zafarkhaja</groupId>
|
||||||
|
<artifactId>java-semver</artifactId>
|
||||||
|
<version>${java-semver.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
package net.kemitix.gitdb;
|
package net.kemitix.gitdb;
|
||||||
|
|
||||||
|
import com.github.zafarkhaja.semver.Version;
|
||||||
import net.kemitix.gitdb.impl.LocalGitDB;
|
import net.kemitix.gitdb.impl.LocalGitDB;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -34,6 +35,12 @@ import java.util.Optional;
|
||||||
*/
|
*/
|
||||||
public interface GitDB {
|
public interface GitDB {
|
||||||
|
|
||||||
|
int MAJOR = 1;
|
||||||
|
int MINOR = 0;
|
||||||
|
int PATCH = 0;
|
||||||
|
|
||||||
|
Version VERSION = Version.forIntegers(MAJOR, MINOR, PATCH);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise a new local gitdb.
|
* Initialise a new local gitdb.
|
||||||
*
|
*
|
||||||
|
@ -71,4 +78,5 @@ public interface GitDB {
|
||||||
* @throws IOException if there is an error accessing the branch name
|
* @throws IOException if there is an error accessing the branch name
|
||||||
*/
|
*/
|
||||||
Optional<GitDBBranch> branch(String name) throws IOException;
|
Optional<GitDBBranch> branch(String name) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
package net.kemitix.gitdb;
|
package net.kemitix.gitdb;
|
||||||
|
|
||||||
|
import com.github.zafarkhaja.semver.Version;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -58,4 +60,14 @@ public interface GitDBBranch {
|
||||||
* @throws IOException if there was an error removing the key/value
|
* @throws IOException if there was an error removing the key/value
|
||||||
*/
|
*/
|
||||||
GitDBBranch remove(String key) throws IOException;
|
GitDBBranch remove(String key) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the GitDB format for the current branch.
|
||||||
|
*
|
||||||
|
* <p>Different branches can have different versions.</p>
|
||||||
|
*
|
||||||
|
* @return the format as per semantic versioning, i.e. "x.y.z" within an Optional
|
||||||
|
* @throws IOException error reading version
|
||||||
|
*/
|
||||||
|
Optional<Version> getFormatVersion() throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
package net.kemitix.gitdb.impl;
|
package net.kemitix.gitdb.impl;
|
||||||
|
|
||||||
|
import com.github.zafarkhaja.semver.Version;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.kemitix.gitdb.GitDBBranch;
|
import net.kemitix.gitdb.GitDBBranch;
|
||||||
|
@ -99,6 +100,12 @@ class GitDBBranchImpl implements GitDBBranch {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Version> getFormatVersion() throws IOException {
|
||||||
|
return gitDBRepo.readValue(branchRef, "GitDB.Version")
|
||||||
|
.map(Version::valueOf);
|
||||||
|
}
|
||||||
|
|
||||||
private String commitMessageForAdd(final String key, final String value) {
|
private String commitMessageForAdd(final String key, final String value) {
|
||||||
return String.format("Add key [%s] = [%s]", key, value);
|
return String.format("Add key [%s] = [%s]", key, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
package net.kemitix.gitdb.impl;
|
package net.kemitix.gitdb.impl;
|
||||||
|
|
||||||
|
import net.kemitix.gitdb.GitDB;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.lib.RepositoryCache;
|
import org.eclipse.jgit.lib.RepositoryCache;
|
||||||
|
@ -45,7 +46,7 @@ class InitGitDBRepo {
|
||||||
private static final String INIT_USER = "GitDB";
|
private static final String INIT_USER = "GitDB";
|
||||||
private static final String INIT_EMAIL = "pcampbell@kemitix.net";
|
private static final String INIT_EMAIL = "pcampbell@kemitix.net";
|
||||||
private static final String MASTER = "master";
|
private static final String MASTER = "master";
|
||||||
private static final String IS_GIT_DB = "isGitDB";
|
private static final String GIT_DB_VERSION = "GitDB.Version";
|
||||||
private static final String REFS_HEADS_FORMAT = "refs/heads/%s";
|
private static final String REFS_HEADS_FORMAT = "refs/heads/%s";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,8 +66,9 @@ class InitGitDBRepo {
|
||||||
|
|
||||||
private void createInitialBranchOnMaster(final Repository repository) throws IOException {
|
private void createInitialBranchOnMaster(final Repository repository) throws IOException {
|
||||||
final GitDBRepo repo = new GitDBRepo(repository);
|
final GitDBRepo repo = new GitDBRepo(repository);
|
||||||
final ObjectId objectId = repo.insertBlob(new byte[0]);
|
final ObjectId objectId =
|
||||||
final ObjectId treeId = repo.insertNewTree(IS_GIT_DB, objectId);
|
repo.insertBlob(GitDB.VERSION.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
final ObjectId treeId = repo.insertNewTree(GIT_DB_VERSION, objectId);
|
||||||
final ObjectId commitId = repo.initialCommit(treeId, INIT_MESSAGE, INIT_USER, INIT_EMAIL);
|
final ObjectId commitId = repo.initialCommit(treeId, INIT_MESSAGE, INIT_USER, INIT_EMAIL);
|
||||||
createBranch(repository, commitId, MASTER);
|
createBranch(repository, commitId, MASTER);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.kemitix.gitdb.test;
|
package net.kemitix.gitdb.test;
|
||||||
|
|
||||||
|
import com.github.zafarkhaja.semver.Version;
|
||||||
import net.kemitix.gitdb.GitDB;
|
import net.kemitix.gitdb.GitDB;
|
||||||
import net.kemitix.gitdb.GitDBBranch;
|
import net.kemitix.gitdb.GitDBBranch;
|
||||||
import net.kemitix.gitdb.InvalidRepositoryException;
|
import net.kemitix.gitdb.InvalidRepositoryException;
|
||||||
|
@ -213,6 +214,18 @@ class GitDBTest implements WithAssertions {
|
||||||
return branchOptional.get();
|
return branchOptional.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When getting the format version it matches expected
|
||||||
|
@Test
|
||||||
|
void getVersionFormat_thenFormatIsSet() throws IOException {
|
||||||
|
//given
|
||||||
|
final GitDBBranch gitDBBranch = gitDBBranch();
|
||||||
|
//when
|
||||||
|
final Optional<Version> formatVersion = gitDBBranch.getFormatVersion();
|
||||||
|
//then
|
||||||
|
assertThat(formatVersion).contains(GitDB.VERSION);
|
||||||
|
assertThat(formatVersion.get()).isNotSameAs(GitDB.VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
// When putting a key/value pair then a GitDbBranch is returned
|
// When putting a key/value pair then a GitDbBranch is returned
|
||||||
@Test
|
@Test
|
||||||
void putValue_thenReturnUpdatedGitDBBranch() throws IOException {
|
void putValue_thenReturnUpdatedGitDBBranch() throws IOException {
|
||||||
|
|
Loading…
Reference in a new issue