mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
RepoUtils実装WIP
This commit is contained in:
parent
8de21d751e
commit
5b227ee089
|
@ -4,16 +4,40 @@ import org.eclipse.jgit.internal.storage.file.FileRepository;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
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 {
|
public class RepoUtils {
|
||||||
// Internal Utils
|
// Internal Utils
|
||||||
|
|
||||||
public Repository createRepo(String id, ) {
|
@Inject
|
||||||
Repository repository = FileRepositoryBuilder.create(
|
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) {
|
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) {
|
public String getRepoName(Repository repo) {
|
||||||
return repo.getDirectory().getParentFile().getName();
|
return repo.getDirectory().getParentFile().getName();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user