InitGitDBRepo.create: rewrite to use new Result methods
This commit is contained in:
parent
d702968b94
commit
88bbfd428b
1 changed files with 5 additions and 11 deletions
|
@ -29,7 +29,6 @@ import org.eclipse.jgit.lib.RepositoryCache;
|
||||||
import org.eclipse.jgit.util.FS;
|
import org.eclipse.jgit.util.FS;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
|
|
||||||
|
@ -52,19 +51,14 @@ class InitGitDBRepo {
|
||||||
*
|
*
|
||||||
* @param dbDir the directory to initialise the repo in
|
* @param dbDir the directory to initialise the repo in
|
||||||
*/
|
*/
|
||||||
static Result<Void> create(final Path dbDir) {
|
static Result<Repository> create(final Path dbDir) {
|
||||||
final InitGitDBRepo initRepo = new InitGitDBRepo();
|
final InitGitDBRepo initRepo = new InitGitDBRepo();
|
||||||
return initRepo.validDbDir(dbDir.toFile())
|
return initRepo.validDbDir(dbDir.toFile())
|
||||||
.peek(File::mkdirs)
|
.peek(File::mkdirs)
|
||||||
.flatMap(dir -> {
|
.map(dir -> RepositoryCache.FileKey.exact(dir, FS.DETECTED))
|
||||||
try (Repository repository = RepositoryCache.FileKey.exact(dir, FS.DETECTED).open(false)) {
|
.andThen(fileKey -> () -> fileKey.open(false))
|
||||||
repository.create(true);
|
.thenWith(repository -> () -> repository.create(true))
|
||||||
initRepo.createInitialBranchOnMaster(repository);
|
.thenWith(repository -> () -> initRepo.createInitialBranchOnMaster(repository));
|
||||||
} catch (IOException e) {
|
|
||||||
return Result.error(e);
|
|
||||||
}
|
|
||||||
return Result.ok(null);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result<File> validDbDir(final File dbDir) {
|
private Result<File> validDbDir(final File dbDir) {
|
||||||
|
|
Loading…
Reference in a new issue