From 5b227ee08902b5ab82fb1462acfbba754051356f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Tue, 12 Dec 2023 11:32:34 +0900 Subject: [PATCH] =?UTF-8?q?RepoUtils=E5=AE=9F=E8=A3=85WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/source/jgit/RepoUtils.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/source/jgit/RepoUtils.java b/data/src/main/java/one/nem/lacerta/source/jgit/RepoUtils.java index 66ce2647..a61767ea 100644 --- a/data/src/main/java/one/nem/lacerta/source/jgit/RepoUtils.java +++ b/data/src/main/java/one/nem/lacerta/source/jgit/RepoUtils.java @@ -4,16 +4,40 @@ import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import java.nio.file.Path; + +import javax.inject.Inject; + +import one.nem.lacerta.utils.repository.FileUtils; + public class RepoUtils { // Internal Utils - public Repository createRepo(String id, ) { - Repository repository = FileRepositoryBuilder.create( + @Inject + FileUtils fileUtils; - ) + + public Repository createRepo(String id) { + Path rootPath = fileUtils.getExternalFilesDirPath(); + + try { + Repository repo = new FileRepository(rootPath.resolve(id).resolve(".git").toFile()); + repo.create(); + return repo; + } catch (Exception e) { + // TODO-rca: handle exception + return null; + } } public Repository getRepo(String id) { - // WIP + Path rootPath = fileUtils.getExternalFilesDirPath(); + try { + Repository repo = new FileRepositoryBuilder().setGitDir(rootPath.resolve(id).resolve(".git").toFile()).build(); + return repo; + } catch (Exception e) { + // TODO-rca: handle exception + return null; + } } public String getRepoName(Repository repo) { return repo.getDirectory().getParentFile().getName();