Refactoring and add headers and javadoc
This commit is contained in:
parent
418bfeaee9
commit
79a5818242
4 changed files with 59 additions and 9 deletions
|
@ -58,16 +58,9 @@ public interface GitDB {
|
||||||
static GitDBLocal openLocal(final Path dbDir) throws IOException {
|
static GitDBLocal openLocal(final Path dbDir) throws IOException {
|
||||||
try {
|
try {
|
||||||
final Git git = Git.open(dbDir.toFile());
|
final Git git = Git.open(dbDir.toFile());
|
||||||
verifyIsBareRepo(dbDir, git);
|
|
||||||
return new GitDBLocal(git);
|
return new GitDBLocal(git);
|
||||||
} catch (RepositoryNotFoundException e) {
|
} catch (RepositoryNotFoundException e) {
|
||||||
throw new GitDBRepoNotFoundException(dbDir, e);
|
throw new GitDBRepoNotFoundException(dbDir, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void verifyIsBareRepo(final Path dbDir, final Git git) {
|
|
||||||
if (!git.getRepository().isBare()) {
|
|
||||||
throw new InvalidRepositoryException("Not a bare repo", dbDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ package net.kemitix.gitdb;
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
import org.eclipse.jgit.api.InitCommand;
|
import org.eclipse.jgit.api.InitCommand;
|
||||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -42,7 +43,7 @@ class GitDBLocal implements GitDB {
|
||||||
private final Git git;
|
private final Git git;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructors a new instance of this class.
|
* Create a new GitDB instance, while initialising a new git repo.
|
||||||
*
|
*
|
||||||
* @param initCommand a JGit InitCommand
|
* @param initCommand a JGit InitCommand
|
||||||
* @param dbDir the path to instantiate the git repo in
|
* @param dbDir the path to instantiate the git repo in
|
||||||
|
@ -58,8 +59,21 @@ class GitDBLocal implements GitDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new GitDB instance using the Git repo.
|
||||||
|
*
|
||||||
|
* @param git the Git handle for the repo
|
||||||
|
*/
|
||||||
GitDBLocal(final Git git) {
|
GitDBLocal(final Git git) {
|
||||||
this.git = git;
|
this.git = verifyIsBareRepo(git);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Git verifyIsBareRepo(final Git git) {
|
||||||
|
final Repository repository = git.getRepository();
|
||||||
|
if (repository.isBare()) {
|
||||||
|
return git;
|
||||||
|
}
|
||||||
|
throw new InvalidRepositoryException("Not a bare repo", repository.getDirectory().toPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateDbDir(final File dbDir) throws IOException {
|
private void validateDbDir(final File dbDir) throws IOException {
|
||||||
|
|
|
@ -1,3 +1,24 @@
|
||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2018 Paul Campbell
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||||
|
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||||
|
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies
|
||||||
|
or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
package net.kemitix.gitdb;
|
package net.kemitix.gitdb;
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
@ -14,6 +35,7 @@ public class GitDBRepoNotFoundException extends RuntimeException {
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
* @param path the location where a GitDB repo was not found
|
||||||
* @param cause the original exception
|
* @param cause the original exception
|
||||||
*/
|
*/
|
||||||
GitDBRepoNotFoundException(final Path path, final RepositoryNotFoundException cause) {
|
GitDBRepoNotFoundException(final Path path, final RepositoryNotFoundException cause) {
|
||||||
|
|
|
@ -1,3 +1,24 @@
|
||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2018 Paul Campbell
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||||
|
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||||
|
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies
|
||||||
|
or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
package net.kemitix.gitdb;
|
package net.kemitix.gitdb;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
Loading…
Reference in a new issue